FileApiClientImpl extends TokenProviderAwareClient implements FileApiClient { @Override public FileLastModified getLastModified(FileLastModifiedParameterBuilder builder) throws SmartlingApiException { final HttpGet httpGet = new HttpGet(buildUrl(getApiUrl(FILES_API_V2_FILE_LAST_MODIFIED), buildParamsQuery( builder.getNameValueList().toArray(new NameValuePair[builder.getNameValueList().size()]) ) ) ); final StringResponse response = executeRequest(httpGet); return getApiV2Response(response.getContents(), new TypeToken<ApiV2ResponseWrapper<FileLastModified>>() { } ).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 testGetLastModified() throws Exception { when(response.getContents()).thenReturn(ResponseExamples.LAST_MODIFICATION_RESPONSE); FileLastModified apiResponse = fileApiClient.getLastModified(new FileLastModifiedParameterBuilder(FILE_URI)); HttpRequestBase request = requestCaptor.getValue(); assertEquals(EXPECTED_AUTHORIZATION_HEADER, request.getFirstHeader(HttpHeaders.AUTHORIZATION).getValue()); assertEquals(HttpGet.class, request.getClass()); assertEquals("https: assertEquals(5, apiResponse.getItems().size()); assertEquals(5, apiResponse.getTotalCount()); assertEquals("be-BY", apiResponse.getItems().get(0).getLocaleId()); assertEquals(DateFormatter.parse("2015-09-15T21:24:42+0000").getTime(), apiResponse.getItems().get(0).getLastModified().getTime()); }
@Test public void testGetLastModifiedWhenGetWrongResponse() throws Exception { when(response.getContents()).thenReturn(ResponseExamples.NOT_EXISTING_CODE_RESPONSE); expectedException.expect(SmartlingApiException.class); expectedException.expectMessage("Response hasn't been parsed correctly [response="); fileApiClient.getLastModified(new FileLastModifiedParameterBuilder(FILE_URI)); }
@Test public void testGetLastModifiedShouldThrowSmartlingApiExceptionWhenEmptyContent() throws Exception { when(response.getContents()).thenReturn(""); expectedException.expect(SmartlingApiException.class); expectedException.expectMessage("Response hasn't been parsed correctly [response="); fileApiClient.getLastModified(new FileLastModifiedParameterBuilder(FILE_URI)); }
@Test public void testGetLastModifiedShouldThrowSmartlingApiExceptionWhenInvalidJson() throws Exception { when(response.getContents()).thenReturn("<b>This is not JSON</b>"); expectedException.expect(SmartlingApiException.class); expectedException.expectMessage("Can't parse response as JSON [response="); fileApiClient.getLastModified(new FileLastModifiedParameterBuilder(FILE_URI)); }