public File getCacheFolder(String workflowName) { // This should probably be replaced. I'm sure a util in JIRA already has a better way to // sanitize. String folderName = workflowName.replaceAll("[:\\\\/*?|<> _]", "-"); File baseFolder = new File(jiraHome.getCachesDirectory(), BASE_CACHE_FOLDER); return new File(baseFolder, folderName); }
private String getDataFilePath(String dataFileName) { // let's do some funky URL stuff to find the real path of this file final URL url = ClassLoaderUtils.getResource( JiraTestUtil.TESTS_BASE + "/action/admin/" + dataFileName, TestDefaultDataImportService.class); final File f = new File(url.getPath()); expect(mockJiraHome.getImportDirectory()).andReturn(new File(f.getParent())).anyTimes(); return f.getAbsolutePath(); }
@Test public void testNoAO() throws Exception { expect(mockBeanFactory.getInstance(currentUser)).andReturn(mockI18nHelper).anyTimes(); expect(mockPermissionManager.hasPermission(Permissions.SYSTEM_ADMIN, currentUser)) .andReturn(true); expect(mockJiraHome.getImportDirectory()).andReturn(new File("somewhere")).anyTimes(); expect(mockI18nHelper.getText("data.import.error.no.ao")).andReturn("Data Import."); backup = null; try { final String filePath = getDataFilePath("jira-export-test.xml"); final DataImportParams params = new DataImportParams.Builder(filePath).build(); executeTest(params, false, DataImportService.ImportError.NONE); fail("Calling doImport with invalid validation result should have thrown an exception!"); } catch (IllegalStateException e) { // yay } }
@Test public void testFileNonExistent() throws Exception { expect(mockBeanFactory.getInstance(currentUser)).andReturn(mockI18nHelper).anyTimes(); expect(mockPermissionManager.hasPermission(Permissions.SYSTEM_ADMIN, currentUser)) .andReturn(true); expect(mockJiraHome.getImportDirectory()).andReturn(new File("somewhere")).anyTimes(); expect( mockI18nHelper.getText( EasyMock.eq("admin.errors.could.not.find.file"), EasyMock.<String>anyObject())) .andReturn("File does not exist."); try { final DataImportParams params = new DataImportParams.Builder("idontexisthopefully.txt").build(); executeTest(params, false, DataImportService.ImportError.NONE); fail("Calling doImport with invalid validation result should have thrown an exception!"); } catch (IllegalStateException e) { // yay } }