FileApiClientImpl extends TokenProviderAwareClient implements FileApiClient { @Override public FileImportSmartlingData importTranslations(FileImportParameterBuilder fileImportParameterBuilder) throws SmartlingApiException { FileBody fileBody = new FileBody(fileImportParameterBuilder.getFile(), createContentType(fileImportParameterBuilder.getFileType(), Charset.forName(fileImportParameterBuilder.getCharset())), fileImportParameterBuilder.getFile().getName()); final List<NameValuePair> paramsList = fileImportParameterBuilder.getNameValueList(); final MultipartEntityBuilder multipartEntityBuilder = MultipartEntityBuilder.create().addPart(FileApiParameter.FILE, fileBody); if (CollectionUtils.isNotEmpty(paramsList)) { for (NameValuePair param : paramsList) { if (param.getValue() != null) { multipartEntityBuilder.addPart( param.getName(), new StringBody( param.getValue(), ContentType.create(TEXT_PLAIN_TYPE, Charset.forName(CharEncoding.UTF_8)) ) ); } } } final HttpPost httpPost = new HttpPost(baseUrl + String.format(FILES_API_V2_FILE_IMPORT, projectId, fileImportParameterBuilder.getLocale())); httpPost.setEntity(multipartEntityBuilder.build()); final StringResponse response = executeRequest(httpPost); return getApiV2Response(response.getContents(), new TypeToken<ApiV2ResponseWrapper<FileImportSmartlingData>>() { } ).retrieveData(); } private  FileApiClientImpl(final TokenProvider tokenProvider, final String projectId, final ProxyConfiguration proxyConfiguration,
                              final String baseUrl, final HttpClientConfiguration httpClientConfiguration); @Override UploadFileData uploadFile(File fileToUpload, FileUploadParameterBuilder fileUploadParameterBuilder); @Override UploadFileData uploadFile(InputStream inputStream, String fileName, FileUploadParameterBuilder fileUploadParameterBuilder); @Override EmptyResponse deleteFile(String fileUri); @Override EmptyResponse renameFile(String fileUri, String newFileUri); @Override FileLastModified getLastModified(FileLastModifiedParameterBuilder builder); @Override StringResponse getFilesArchive(GetFilesArchiveParameterBuilder builder); @Override StringResponse getFile(GetFileParameterBuilder getFileParameterBuilder); @Override StringResponse getOriginalFile(GetOriginalFileParameterBuilder getFileParameterBuilder); @Override FileList getFilesList(FileListSearchParameterBuilder fileListSearchParameterBuilder); @Override FileLocaleStatus getFileLocaleStatus(String fileUri, String locale); @Override FileStatus getFileStatus(String fileUri); @Override FileImportSmartlingData importTranslations(FileImportParameterBuilder fileImportParameterBuilder);  }
@Test public void testImportTranslations() throws Exception { when(response.getContents()).thenReturn(ResponseExamples.IMPORT_TRANSLATIONS_RESPONSE); FileImportSmartlingData apiResponse = fileApiClient .importTranslations(new FileImportParameterBuilder(mock(File.class), LOCALE, CHARSET, FileType.CSV, FILE_URI)); HttpRequestBase request = requestCaptor.getValue(); assertEquals(EXPECTED_AUTHORIZATION_HEADER, request.getFirstHeader(HttpHeaders.AUTHORIZATION).getValue()); assertEquals(HttpPost.class, request.getClass()); assertEquals("https: assertEquals(0, apiResponse.getStringCount()); assertEquals(0, apiResponse.getTranslationImportErrors().size()); }