@Test public void testProcessUploadedFileShouldGetFileNameFromPathWhichContainsSlash() { given(stubResourcePathProvider.getTemplatesPathAsString()).willReturn(""); underTest.processUploadedFile(resource, "some-content-type", "stub-template", FILE_PATH_W_SLASH); verify(fileWriter).write(resource, "/" + FILE_PATH, EXCEPTION_MESSAGE); }
public String processUploadedFile(final InputStream resource, final String contentType, final String fieldName, final String fileName) { String result; String resFileName = extractFileNameFromAbsolutePath(fileName); String classUploadResult = processUploadedClasses(resource, contentType, fieldName, resFileName); if (classUploadResult != null) { result = classUploadResult; } else { if ("stub-configuration".equals(fieldName) && JSON_CONTENT_TYPE.equals(contentType)) { try { routingService.performModification(new NewStubDescriptorCommand(resource, stubConfigurationJsonBuilder, sequenceDescriptorHolder)); serviceMap.detectServices(); } catch (ClassNotFoundException e) { result = "Uploading " + fileName + " failed with ClassNotFoundException."; throw new CannotUploadExternalResourceException(result, e); } result = "New stub configuration was uploaded to Wilma."; } else if ("stub-template".equals(fieldName)) { writeResourceToFile(resource, resFileName, stubResourcePathProvider.getTemplatesPathAsString()); result = "External template '" + resFileName + "' was uploaded to Wilma."; } else { result = "Uploading " + fileName + " failed: wrong content type or tried to upload file from unauthorized form!"; throw new CannotUploadExternalResourceException(result); } } return result; }
MultiPartFileProcessor { public String processUploadedFile(final InputStream resource, final String contentType, final String fieldName, final String fileName) { String result; String resFileName = extractFileNameFromAbsolutePath(fileName); String classUploadResult = processUploadedClasses(resource, contentType, fieldName, resFileName); if (classUploadResult != null) { result = classUploadResult; } else { if ("stub-configuration".equals(fieldName) && JSON_CONTENT_TYPE.equals(contentType)) { try { routingService.performModification(new NewStubDescriptorCommand(resource, stubConfigurationJsonBuilder, sequenceDescriptorHolder)); serviceMap.detectServices(); } catch (ClassNotFoundException e) { result = "Uploading " + fileName + " failed with ClassNotFoundException."; throw new CannotUploadExternalResourceException(result, e); } result = "New stub configuration was uploaded to Wilma."; } else if ("stub-template".equals(fieldName)) { writeResourceToFile(resource, resFileName, stubResourcePathProvider.getTemplatesPathAsString()); result = "External template '" + resFileName + "' was uploaded to Wilma."; } else { result = "Uploading " + fileName + " failed: wrong content type or tried to upload file from unauthorized form!"; throw new CannotUploadExternalResourceException(result); } } return result; } }
MultiPartFileProcessor { public String processUploadedFile(final InputStream resource, final String contentType, final String fieldName, final String fileName) { String result; String resFileName = extractFileNameFromAbsolutePath(fileName); String classUploadResult = processUploadedClasses(resource, contentType, fieldName, resFileName); if (classUploadResult != null) { result = classUploadResult; } else { if ("stub-configuration".equals(fieldName) && JSON_CONTENT_TYPE.equals(contentType)) { try { routingService.performModification(new NewStubDescriptorCommand(resource, stubConfigurationJsonBuilder, sequenceDescriptorHolder)); serviceMap.detectServices(); } catch (ClassNotFoundException e) { result = "Uploading " + fileName + " failed with ClassNotFoundException."; throw new CannotUploadExternalResourceException(result, e); } result = "New stub configuration was uploaded to Wilma."; } else if ("stub-template".equals(fieldName)) { writeResourceToFile(resource, resFileName, stubResourcePathProvider.getTemplatesPathAsString()); result = "External template '" + resFileName + "' was uploaded to Wilma."; } else { result = "Uploading " + fileName + " failed: wrong content type or tried to upload file from unauthorized form!"; throw new CannotUploadExternalResourceException(result); } } return result; }  }
MultiPartFileProcessor { public String processUploadedFile(final InputStream resource, final String contentType, final String fieldName, final String fileName) { String result; String resFileName = extractFileNameFromAbsolutePath(fileName); String classUploadResult = processUploadedClasses(resource, contentType, fieldName, resFileName); if (classUploadResult != null) { result = classUploadResult; } else { if ("stub-configuration".equals(fieldName) && JSON_CONTENT_TYPE.equals(contentType)) { try { routingService.performModification(new NewStubDescriptorCommand(resource, stubConfigurationJsonBuilder, sequenceDescriptorHolder)); serviceMap.detectServices(); } catch (ClassNotFoundException e) { result = "Uploading " + fileName + " failed with ClassNotFoundException."; throw new CannotUploadExternalResourceException(result, e); } result = "New stub configuration was uploaded to Wilma."; } else if ("stub-template".equals(fieldName)) { writeResourceToFile(resource, resFileName, stubResourcePathProvider.getTemplatesPathAsString()); result = "External template '" + resFileName + "' was uploaded to Wilma."; } else { result = "Uploading " + fileName + " failed: wrong content type or tried to upload file from unauthorized form!"; throw new CannotUploadExternalResourceException(result); } } return result; }  String processUploadedFile(final InputStream resource, final String contentType, final String fieldName, final String fileName); }
MultiPartFileProcessor { public String processUploadedFile(final InputStream resource, final String contentType, final String fieldName, final String fileName) { String result; String resFileName = extractFileNameFromAbsolutePath(fileName); String classUploadResult = processUploadedClasses(resource, contentType, fieldName, resFileName); if (classUploadResult != null) { result = classUploadResult; } else { if ("stub-configuration".equals(fieldName) && JSON_CONTENT_TYPE.equals(contentType)) { try { routingService.performModification(new NewStubDescriptorCommand(resource, stubConfigurationJsonBuilder, sequenceDescriptorHolder)); serviceMap.detectServices(); } catch (ClassNotFoundException e) { result = "Uploading " + fileName + " failed with ClassNotFoundException."; throw new CannotUploadExternalResourceException(result, e); } result = "New stub configuration was uploaded to Wilma."; } else if ("stub-template".equals(fieldName)) { writeResourceToFile(resource, resFileName, stubResourcePathProvider.getTemplatesPathAsString()); result = "External template '" + resFileName + "' was uploaded to Wilma."; } else { result = "Uploading " + fileName + " failed: wrong content type or tried to upload file from unauthorized form!"; throw new CannotUploadExternalResourceException(result); } } return result; }  String processUploadedFile(final InputStream resource, final String contentType, final String fieldName, final String fileName);  }