Removed unnecessary diffs from master and applied code formatter to all diffs

This commit is contained in:
RobinFleige
2018-08-16 11:09:36 +02:00
parent e9a9c852c5
commit e425e2108e
19 changed files with 91 additions and 73 deletions
@@ -149,7 +149,7 @@ public abstract class EventDialog extends DataEntryDialogWithDateTimeBox<EventDT
StringMessages stringMessages, List<LeaderboardGroupDTO> availableLeaderboardGroups, StringMessages stringMessages, List<LeaderboardGroupDTO> availableLeaderboardGroups,
Iterable<LeaderboardGroupDTO> leaderboardGroupsOfEvent, DialogCallback<EventDTO> callback) { Iterable<LeaderboardGroupDTO> leaderboardGroupsOfEvent, DialogCallback<EventDTO> callback) {
super(stringMessages.event(), null, stringMessages.ok(), stringMessages.cancel(), validator, callback); super(stringMessages.event(), null, stringMessages.ok(), stringMessages.cancel(), validator, callback);
testFileStorageService(sailingService);//callback: the earlier the better to improve user experience testFileStorageService(sailingService);
this.stringMessages = stringMessages; this.stringMessages = stringMessages;
this.availableLeaderboardGroupsByName = new HashMap<>(); this.availableLeaderboardGroupsByName = new HashMap<>();
for (final LeaderboardGroupDTO lgDTO : availableLeaderboardGroups) { for (final LeaderboardGroupDTO lgDTO : availableLeaderboardGroups) {
@@ -470,17 +470,18 @@ public class EventListComposite extends Composite implements EventsRefresher, Le
List<EventDTO> existingEvents = new ArrayList<EventDTO>(eventListDataProvider.getList()); List<EventDTO> existingEvents = new ArrayList<EventDTO>(eventListDataProvider.getList());
final List<LeaderboardGroupDTO> existingLeaderboardGroups = new ArrayList<LeaderboardGroupDTO>(); final List<LeaderboardGroupDTO> existingLeaderboardGroups = new ArrayList<LeaderboardGroupDTO>();
Util.addAll(availableLeaderboardGroups, existingLeaderboardGroups); Util.addAll(availableLeaderboardGroups, existingLeaderboardGroups);
EventCreateDialog dialog = new EventCreateDialog(Collections.unmodifiableCollection(existingEvents), existingLeaderboardGroups, EventCreateDialog dialog = new EventCreateDialog(Collections.unmodifiableCollection(existingEvents),
sailingService, stringMessages, errorReporter, new DialogCallback<EventDTO>() { existingLeaderboardGroups, sailingService, stringMessages, errorReporter,
@Override new DialogCallback<EventDTO>() {
public void cancel() { @Override
} public void cancel() {
}
@Override @Override
public void ok(final EventDTO newEvent) { public void ok(final EventDTO newEvent) {
createNewEvent(newEvent, existingLeaderboardGroups); createNewEvent(newEvent, existingLeaderboardGroups);
} }
}); });
dialog.ensureDebugId("EventCreateDialog"); dialog.ensureDebugId("EventCreateDialog");
dialog.show(); dialog.show();
} }
@@ -593,7 +594,7 @@ public class EventListComposite extends Composite implements EventsRefresher, Le
existingEvents.remove(selectedEvent); existingEvents.remove(selectedEvent);
List<LeaderboardGroupDTO> existingLeaderboardGroups = new ArrayList<LeaderboardGroupDTO>(); List<LeaderboardGroupDTO> existingLeaderboardGroups = new ArrayList<LeaderboardGroupDTO>();
Util.addAll(availableLeaderboardGroups, existingLeaderboardGroups); Util.addAll(availableLeaderboardGroups, existingLeaderboardGroups);
EventEditDialog dialog = new EventEditDialog(selectedEvent, Collections.unmodifiableCollection(existingEvents), EventEditDialog dialog = new EventEditDialog(selectedEvent, Collections.unmodifiableCollection(existingEvents),
existingLeaderboardGroups, sailingService, stringMessages, errorReporter, existingLeaderboardGroups, sailingService, stringMessages, errorReporter,
new DialogCallback<EventDTO>() { new DialogCallback<EventDTO>() {
@Override @Override
@@ -58,12 +58,11 @@ public abstract class ImageDialog extends DataEntryDialog<ImageDTO> {
protected static class ImageParameterValidator implements Validator<ImageDTO> { protected static class ImageParameterValidator implements Validator<ImageDTO> {
private StringMessages stringMessages; private StringMessages stringMessages;
private List<CheckBox> doResize; private List<CheckBox> doResize;
public ImageParameterValidator(StringMessages stringMessages, ArrayList<CheckBox> doResize) { public ImageParameterValidator(StringMessages stringMessages, ArrayList<CheckBox> doResize) {
this.stringMessages = stringMessages; this.stringMessages = stringMessages;
this.doResize = doResize; this.doResize = doResize;
} }
@Override @Override
public String getErrorMessage(ImageDTO imageToValidate) { public String getErrorMessage(ImageDTO imageToValidate) {
String errorMessage = null; String errorMessage = null;
@@ -252,7 +251,7 @@ public abstract class ImageDialog extends DataEntryDialog<ImageDTO> {
} }
}); });
} }
@Override @Override
protected ImageDTO getResult() { protected ImageDTO getResult() {
List<String> tags = new ArrayList<String>(); List<String> tags = new ArrayList<String>();
@@ -0,0 +1,9 @@
diff a/java/com.sap.sailing.gwt.ui/src/main/java/com/sap/sailing/gwt/ui/adminconsole/ImageDialog.java b/java/com.sap.sailing.gwt.ui/src/main/java/com/sap/sailing/gwt/ui/adminconsole/ImageDialog.java (rejected hunks)
@@ -58,6 +58,7 @@
protected static class ImageParameterValidator implements Validator<ImageDTO> {
private StringMessages stringMessages;
private List<CheckBox> doResize;
+
public ImageParameterValidator(StringMessages stringMessages, ArrayList<CheckBox> doResize) {
this.stringMessages = stringMessages;
this.doResize = doResize;
@@ -158,12 +158,12 @@ public class ImagesListComposite extends Composite {
public SafeHtml getValue(ImageDTO image) { public SafeHtml getValue(ImageDTO image) {
String linkName = ""; String linkName = "";
String link = image.getSourceRef(); String link = image.getSourceRef();
if (link.endsWith("/")) { if(link.endsWith("/")) {
link = link.substring(0, link.length() - 1); link = link.substring(0, link.length() - 1);
} }
int index = link.lastIndexOf("/"); int index = link.lastIndexOf("/");
if (index > 0) { if(index > 0) {
linkName = link.substring(index + 1, link.length()); linkName = link.substring(index+1, link.length());
} }
return ANCHORTEMPLATE.cell(UriUtils.fromString(image.getSourceRef()), linkName); return ANCHORTEMPLATE.cell(UriUtils.fromString(image.getSourceRef()), linkName);
} }
@@ -247,8 +247,8 @@ public class StructureImportManagementPanel extends SimplePanel implements Regat
} }
private void openEventCreateDialog() { private void openEventCreateDialog() {
EventCreateDialog dialog = new EventCreateDialog(existingEvents, Collections.<LeaderboardGroupDTO>emptyList(), sailingService, stringMessages, errorReporter, EventCreateDialog dialog = new EventCreateDialog(existingEvents, Collections.<LeaderboardGroupDTO> emptyList(),
new DialogCallback<EventDTO>() { sailingService, stringMessages, errorReporter, new DialogCallback<EventDTO>() {
@Override @Override
public void cancel() { public void cancel() {
} }
@@ -252,7 +252,7 @@ public class VideosListComposite extends Composite {
} }
private void openCreateVideoDialog(String initialTag) { private void openCreateVideoDialog(String initialTag) {
if(!storageServiceAvailable.getValue()) { if (!storageServiceAvailable.getValue()) {
Notification.notify(stringMessages.setUpStorageService(), NotificationType.ERROR); Notification.notify(stringMessages.setUpStorageService(), NotificationType.ERROR);
return; return;
} }
@@ -271,7 +271,7 @@ public class VideosListComposite extends Composite {
} }
private void openEditVideoDialog(final VideoDTO selectedVideo) { private void openEditVideoDialog(final VideoDTO selectedVideo) {
if(!storageServiceAvailable.getValue()) { if (!storageServiceAvailable.getValue()) {
Notification.notify(stringMessages.setUpStorageService(), NotificationType.ERROR); Notification.notify(stringMessages.setUpStorageService(), NotificationType.ERROR);
return; return;
} }
@@ -2095,11 +2095,11 @@ public interface StringMessages extends com.sap.sse.gwt.client.StringMessages,
String manage2SailEventURLBox(); String manage2SailEventURLBox();
String manage2SailEventIdBoxTooltip(); String manage2SailEventIdBoxTooltip();
String manage2SailPort(); String manage2SailPort();
String allowResizing();
String windFinderSpotCollectionsList(); String windFinderSpotCollectionsList();
String swissTimingUpdateURL(); String swissTimingUpdateURL();
String swissTimingUpdateUsername(); String swissTimingUpdateUsername();
String swissTimingUpdatePassword(); String swissTimingUpdatePassword();
String allowResizing();
String resizeSuccessfull(); String resizeSuccessfull();
String resizeUnsuccessfull(); String resizeUnsuccessfull();
String setUpStorageService(); String setUpStorageService();
@@ -0,0 +1,9 @@
diff a/java/com.sap.sailing.gwt.ui/src/main/java/com/sap/sailing/gwt/ui/client/StringMessages_de.properties b/java/com.sap.sailing.gwt.ui/src/main/java/com/sap/sailing/gwt/ui/client/StringMessages_de.properties (rejected hunks)
@@ -2088,6 +2088,5 @@
manage2SailPort=Port
swissTimingUpdateURL=Update URL (z.B. für Startzeit-Übertragung)
swissTimingUpdateUsername=Benutzername zum Versenden der Updates
-swissTimingUpdatePassword=Passwort zum Versenden der Updates
\ No newline at end of file
swissTimingUpdatePassword=Passwort zum Versenden der UpdatesswissTimingUpdatePassword=Passwort zum Versenden der UpdatesswissTimingUpdatePassword=Passwort zum Versenden der Updates
allowResizing=Skalierung erlauben
@@ -7893,21 +7893,24 @@ public class SailingServiceImpl extends ProxiedRemoteServiceServlet implements S
public ImageDTO[] resizeImage(ToResizeImageDTO toResizeImage) throws Exception { public ImageDTO[] resizeImage(ToResizeImageDTO toResizeImage) throws Exception {
// In following size tag will describe the tags, that have a defined size in MediaConstants, which is LOGO, // In following size tag will describe the tags, that have a defined size in MediaConstants, which is LOGO,
// TEASER and STAGE at the moment // TEASER and STAGE at the moment
//create ArrayList that will contain all images that are to return // create ArrayList that will contain all images that are to return
List<ImageDTO> resizedImages = new ArrayList<ImageDTO>(); List<ImageDTO> resizedImages = new ArrayList<ImageDTO>();
// calculating the fileType of the image by its uri // calculating the fileType of the image by its uri
String fileType = toResizeImage.getSourceRef().substring(toResizeImage.getSourceRef().lastIndexOf(".")+1); String fileType = toResizeImage.getSourceRef().substring(toResizeImage.getSourceRef().lastIndexOf(".") + 1);
// deleting all size-tags from the tags list, because after resizing there should only be one size tag per image // deleting all size-tags from the tags list, because after resizing there should only be one size tag per image
toResizeImage.getTags().removeAll(toResizeImage.getMap().keySet()); toResizeImage.getTags().removeAll(toResizeImage.getMap().keySet());
//Create ImageConverter for further use // Create ImageConverter for further use
ImageConverter converter = new ImageConverter(HttpUrlConnectionHelper.redirectConnection(new URL(toResizeImage.getSourceRef())).getInputStream(), fileType, toResizeImage.getMap()); ImageConverter converter = new ImageConverter(
HttpUrlConnectionHelper.redirectConnection(new URL(toResizeImage.getSourceRef())).getInputStream(),
fileType, toResizeImage.getMap());
addImagesThatNeedResizing(converter, resizedImages, toResizeImage); addImagesThatNeedResizing(converter, resizedImages, toResizeImage);
addImagesThatDoNotNeedResizing(converter, resizedImages, toResizeImage); addImagesThatDoNotNeedResizing(converter, resizedImages, toResizeImage);
return resizedImages.toArray(new ImageDTO[resizedImages.size()]); return resizedImages.toArray(new ImageDTO[resizedImages.size()]);
} }
private void addImagesThatDoNotNeedResizing(ImageConverter converter, List<ImageDTO> resizedImages, ToResizeImageDTO toResizeImage) { private void addImagesThatDoNotNeedResizing(ImageConverter converter, List<ImageDTO> resizedImages,
// if there is no size tag that does not need a resize we can delete the original source ToResizeImageDTO toResizeImage) {
// if there is no size tag that does not need a resize we can delete the original source
if (converter.getNotResizeSizeTags().isEmpty()) { if (converter.getNotResizeSizeTags().isEmpty()) {
try { try {
getService().getFileStorageManagementService().getActiveFileStorageService() getService().getFileStorageManagementService().getActiveFileStorageService()
@@ -7930,7 +7933,8 @@ public class SailingServiceImpl extends ProxiedRemoteServiceServlet implements S
} }
} }
private void addImagesThatNeedResizing(ImageConverter converter, List<ImageDTO> resizedImages, ToResizeImageDTO toResizeImage) throws Exception{ private void addImagesThatNeedResizing(ImageConverter converter, List<ImageDTO> resizedImages,
ToResizeImageDTO toResizeImage) throws Exception {
// iterating over every size-tag that needs a resize // iterating over every size-tag that needs a resize
for (String resizeTag : converter.getResizeTags()) { for (String resizeTag : converter.getResizeTags()) {
// creating a new ImageDTO object with all values from the ToResizeImageDTO object // creating a new ImageDTO object with all values from the ToResizeImageDTO object
@@ -7943,8 +7947,8 @@ public class SailingServiceImpl extends ProxiedRemoteServiceServlet implements S
image.setSizeInPx(resizedBufferedImage.getWidth(), resizedBufferedImage.getHeight()); image.setSizeInPx(resizedBufferedImage.getWidth(), resizedBufferedImage.getHeight());
// storing the image on FileStorageService // storing the image on FileStorageService
InputStream fileStorageStream = converter.resizedImageToInputStream(resizedBufferedImage); InputStream fileStorageStream = converter.resizedImageToInputStream(resizedBufferedImage);
URI newUri = getService().getFileStorageManagementService().getActiveFileStorageService().storeFile(fileStorageStream, URI newUri = getService().getFileStorageManagementService().getActiveFileStorageService().storeFile(
"." + converter.getImageFormat(), new Long(fileStorageStream.available())); fileStorageStream, "." + converter.getImageFormat(), new Long(fileStorageStream.available()));
// saving the new image ref uri to the ImageDTO object // saving the new image ref uri to the ImageDTO object
image.setSourceRef(newUri.toString()); image.setSourceRef(newUri.toString());
// adding the resized ImageDTO object to arraylist // adding the resized ImageDTO object to arraylist
@@ -7956,14 +7960,12 @@ public class SailingServiceImpl extends ProxiedRemoteServiceServlet implements S
BufferedImage resizedImage = null; BufferedImage resizedImage = null;
switch (resizeTag) { switch (resizeTag) {
case MediaTagConstants.LOGO: case MediaTagConstants.LOGO:
resizedImage = converter.resize(MediaConstants.MIN_LOGO_IMAGE_WIDTH, resizedImage = converter.resize(MediaConstants.MIN_LOGO_IMAGE_WIDTH, MediaConstants.MAX_LOGO_IMAGE_WIDTH,
MediaConstants.MAX_LOGO_IMAGE_WIDTH, MediaConstants.MIN_LOGO_IMAGE_HEIGHT, MediaConstants.MIN_LOGO_IMAGE_HEIGHT, MediaConstants.MAX_LOGO_IMAGE_HEIGHT);
MediaConstants.MAX_LOGO_IMAGE_HEIGHT);
break; break;
case MediaTagConstants.STAGE: case MediaTagConstants.STAGE:
resizedImage = converter.resize(MediaConstants.MIN_STAGE_IMAGE_WIDTH, resizedImage = converter.resize(MediaConstants.MIN_STAGE_IMAGE_WIDTH, MediaConstants.MAX_STAGE_IMAGE_WIDTH,
MediaConstants.MAX_STAGE_IMAGE_WIDTH, MediaConstants.MIN_STAGE_IMAGE_HEIGHT, MediaConstants.MIN_STAGE_IMAGE_HEIGHT, MediaConstants.MAX_STAGE_IMAGE_HEIGHT);
MediaConstants.MAX_STAGE_IMAGE_HEIGHT);
break; break;
case MediaTagConstants.TEASER: case MediaTagConstants.TEASER:
resizedImage = converter.resize(MediaConstants.MIN_EVENTTEASER_IMAGE_WIDTH, resizedImage = converter.resize(MediaConstants.MIN_EVENTTEASER_IMAGE_WIDTH,
@@ -7,11 +7,9 @@ Bundle-Vendor: SAP
Bundle-RequiredExecutionEnvironment: JavaSE-1.8 Bundle-RequiredExecutionEnvironment: JavaSE-1.8
Import-Package: com.sap.sailing.server, Import-Package: com.sap.sailing.server,
com.sap.sailing.server.operationaltransformation, com.sap.sailing.server.operationaltransformation,
com.sap.sse.gwt.client.media,
javax.ws.rs;version="1.1.1", javax.ws.rs;version="1.1.1",
javax.ws.rs.core;version="1.1.1", javax.ws.rs.core;version="1.1.1",
javax.ws.rs.ext;version="1.1.1", javax.ws.rs.ext;version="1.1.1",
org.apache.commons.io;version="2.2.0",
org.apache.commons.lang, org.apache.commons.lang,
org.json.simple, org.json.simple,
org.json.simple.parser, org.json.simple.parser,
@@ -35,7 +35,7 @@ public interface FileStorageService extends IsManagedByCache<FileStorageServiceR
* From the given {@code uri} it should be possible to determine the file to remove. * From the given {@code uri} it should be possible to determine the file to remove.
*/ */
void removeFile(URI uri) throws OperationFailedException, InvalidPropertiesException, IOException; void removeFile(URI uri) throws OperationFailedException, InvalidPropertiesException, IOException;
FileStorageServiceProperty[] getProperties(); FileStorageServiceProperty[] getProperties();
/** /**
@@ -54,7 +54,7 @@ public class AmazonS3FileStorageServiceImpl extends BaseFileStorageServiceImpl i
private AmazonS3Client createS3Client() throws InvalidPropertiesException { private AmazonS3Client createS3Client() throws InvalidPropertiesException {
AWSCredentials creds; AWSCredentials creds;
// first try to use properties // first try to use properties
if (accessId.getValue() != null && accessKey.getValue() != null) { if (accessId.getValue() != null && accessKey.getValue() != null) {
creds = new BasicAWSCredentials(accessId.getValue(), accessKey.getValue()); creds = new BasicAWSCredentials(accessId.getValue(), accessKey.getValue());
@@ -124,7 +124,7 @@ public class AmazonS3FileStorageServiceImpl extends BaseFileStorageServiceImpl i
AmazonS3Client s3 = createS3Client(); AmazonS3Client s3 = createS3Client();
if(bucketName.getValue().equals("")) { if (bucketName.getValue().equals("")) {
throw new InvalidPropertiesException("empty bucketname is not allowed"); throw new InvalidPropertiesException("empty bucketname is not allowed");
} }
// test if credentials are valid // test if credentials are valid
@@ -82,7 +82,7 @@ public class LocalFileStorageServiceImpl extends BaseFileStorageServiceImpl impl
return getUri(fileName); return getUri(fileName);
} }
private static String getKey(String fileEnding) { private static String getKey(String fileEnding) {
String key = UUID.randomUUID().toString(); String key = UUID.randomUUID().toString();
key += fileEnding; key += fileEnding;
@@ -41,4 +41,5 @@ public class DummyFileStorageService extends BaseFileStorageServiceImpl implemen
@Override @Override
public void testProperties() throws InvalidPropertiesException { public void testProperties() throws InvalidPropertiesException {
} }
} }
+1 -2
View File
@@ -12,8 +12,7 @@ Require-Bundle: com.google.gwt.user;bundle-version="2.8.2";resolution:=optional,
com.sap.sse.common, com.sap.sse.common,
com.sap.sse.filestorage com.sap.sse.filestorage
Bundle-ActivationPolicy: lazy Bundle-ActivationPolicy: lazy
Import-Package: com.sap.sse.gwt.client.controls.listedit, Import-Package: javax.servlet;version="3.1.0",
javax.servlet;version="3.1.0",
javax.servlet.descriptor;version="3.1.0", javax.servlet.descriptor;version="3.1.0",
javax.servlet.http;version="3.1.0", javax.servlet.http;version="3.1.0",
org.apache.commons.io, org.apache.commons.io,
@@ -23,9 +23,10 @@ public abstract class GenericStringListInlineEditorWithCheckboxesComposite<Value
private List<CheckBox> checkBoxes; private List<CheckBox> checkBoxes;
private ClickHandler checkBoxClickHandler; private ClickHandler checkBoxClickHandler;
private String checkBoxText; private String checkBoxText;
public ExpandedUi(StringMessages stringMessages, ImageResource removeImage, List<String> suggestValues, public ExpandedUi(StringMessages stringMessages, ImageResource removeImage, List<String> suggestValues,
String placeholderTextForAddTextbox, int textBoxSize, List<CheckBox> checkBoxes, String checkBoxText, ClickHandler clickHandler) { String placeholderTextForAddTextbox, int textBoxSize, List<CheckBox> checkBoxes, String checkBoxText,
ClickHandler clickHandler) {
super(stringMessages, removeImage, suggestValues, placeholderTextForAddTextbox, textBoxSize); super(stringMessages, removeImage, suggestValues, placeholderTextForAddTextbox, textBoxSize);
this.checkBoxes = checkBoxes; this.checkBoxes = checkBoxes;
this.checkBoxClickHandler = clickHandler; this.checkBoxClickHandler = clickHandler;
@@ -37,24 +38,24 @@ public abstract class GenericStringListInlineEditorWithCheckboxesComposite<Value
super.addRow(newValue); super.addRow(newValue);
CheckBox checkBox = new CheckBox(checkBoxText); CheckBox checkBox = new CheckBox(checkBoxText);
checkBoxes.add(checkBox); checkBoxes.add(checkBox);
expandedValuesGrid.setWidget(expandedValuesGrid.getRowCount()-1, 2, checkBox); expandedValuesGrid.setWidget(expandedValuesGrid.getRowCount() - 1, 2, checkBox);
checkBox.setVisible(false); checkBox.setVisible(false);
checkBox.getElement().getStyle().setBackgroundColor("red"); checkBox.getElement().getStyle().setBackgroundColor("red");
checkBox.addClickHandler(checkBoxClickHandler); checkBox.addClickHandler(checkBoxClickHandler);
} }
@Override @Override
public Widget initWidget() { public Widget initWidget() {
expandedValuesGrid = new Grid(0, 3); expandedValuesGrid = new Grid(0, 3);
expandedValuesGrid.ensureDebugId("ExpandedValuesGrid"); expandedValuesGrid.ensureDebugId("ExpandedValuesGrid");
VerticalPanel panel = new VerticalPanel(); VerticalPanel panel = new VerticalPanel();
panel.add(createAddWidget()); panel.add(createAddWidget());
panel.add(expandedValuesGrid); panel.add(expandedValuesGrid);
return panel; return panel;
} }
@Override @Override
public void onRowRemoved(int rowIndex) { public void onRowRemoved(int rowIndex) {
checkBoxes.remove(rowIndex); checkBoxes.remove(rowIndex);
@@ -6,7 +6,7 @@ import java.util.Map;
public class ToResizeImageDTO extends ImageDTO { public class ToResizeImageDTO extends ImageDTO {
Map<String, Boolean> toResizeMap; Map<String, Boolean> toResizeMap;
/** for GWT */ /** for GWT */
protected ToResizeImageDTO() { protected ToResizeImageDTO() {
} }
@@ -15,12 +15,12 @@ public class ToResizeImageDTO extends ImageDTO {
super(imageRef, createdAtDate); super(imageRef, createdAtDate);
this.toResizeMap = toResizeMap; this.toResizeMap = toResizeMap;
} }
public boolean resizeForTag(String tag) { public boolean resizeForTag(String tag) {
return toResizeMap.get(tag); return toResizeMap.get(tag);
} }
public Map<String, Boolean> getMap(){ public Map<String, Boolean> getMap() {
return toResizeMap; return toResizeMap;
} }
} }
@@ -5,35 +5,34 @@ import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull; import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertTrue;
import java.io.ByteArrayInputStream; import java.io.ByteArrayInputStream;
import java.util.HashMap; import java.util.HashMap;
import org.junit.Before; import org.junit.Before;
import org.junit.Test; import org.junit.Test;
import com.sap.sse.util.ImageConverter; import com.sap.sse.util.ImageConverter;
public class ImageConverterTest { public class ImageConverterTest {
private ImageConverter jpgConverter; private ImageConverter jpgConverter;
private ImageConverter pngConverter; private ImageConverter pngConverter;
private final byte[] onePixelPngExample = new byte[]{-119, 80, 78, 71, 13, 10, 26, 10, 0, 0, 0, 13, 73, 72, 68, 82, 0, 0, 0, 1, 0, 0, 0, 1, 8, 2, 0, 0, 0, -112, 119, 83, -34, 0, 0, 0, 12, 73, 68, 65, 84, 120, -38, 99, 96, 96, 96, 0, 0, 0, 4, 0, 1, -56, -22, -21, -7, 0, 0, 0, 0, 73, 69, 78, 68, -82, 66, 96, -126}; private final byte[] onePixelPngExample = new byte[]{-119, 80, 78, 71, 13, 10, 26, 10, 0, 0, 0, 13, 73, 72, 68, 82, 0, 0, 0, 1, 0, 0, 0, 1, 8, 2, 0, 0, 0, -112, 119, 83, -34, 0, 0, 0, 12, 73, 68, 65, 84, 120, -38, 99, 96, 96, 96, 0, 0, 0, 4, 0, 1, -56, -22, -21, -7, 0, 0, 0, 0, 73, 69, 78, 68, -82, 66, 96, -126};
private final byte[] onePixelJpgExample = new byte[]{-1, -40, -1, -32, 0, 16, 74, 70, 73, 70, 0, 1, 2, 0, 0, 1, 0, 1, 0, 0, -1, -37, 0, 67, 0, 8, 6, 6, 7, 6, 5, 8, 7, 7, 7, 9, 9, 8, 10, 12, 20, 13, 12, 11, 11, 12, 25, 18, 19, 15, 20, 29, 26, 31, 30, 29, 26, 28, 28, 32, 36, 46, 39, 32, 34, 44, 35, 28, 28, 40, 55, 41, 44, 48, 49, 52, 52, 52, 31, 39, 57, 61, 56, 50, 60, 46, 51, 52, 50, -1, -37, 0, 67, 1, 9, 9, 9, 12, 11, 12, 24, 13, 13, 24, 50, 33, 28, 33, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, -1, -64, 0, 17, 8, 0, 1, 0, 1, 3, 1, 34, 0, 2, 17, 1, 3, 17, 1, -1, -60, 0, 31, 0, 0, 1, 5, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, -1, -60, 0, -75, 16, 0, 2, 1, 3, 3, 2, 4, 3, 5, 5, 4, 4, 0, 0, 1, 125, 1, 2, 3, 0, 4, 17, 5, 18, 33, 49, 65, 6, 19, 81, 97, 7, 34, 113, 20, 50, -127, -111, -95, 8, 35, 66, -79, -63, 21, 82, -47, -16, 36, 51, 98, 114, -126, 9, 10, 22, 23, 24, 25, 26, 37, 38, 39, 40, 41, 42, 52, 53, 54, 55, 56, 57, 58, 67, 68, 69, 70, 71, 72, 73, 74, 83, 84, 85, 86, 87, 88, 89, 90, 99, 100, 101, 102, 103, 104, 105, 106, 115, 116, 117, 118, 119, 120, 121, 122, -125, -124, -123, -122, -121, -120, -119, -118, -110, -109, -108, -107, -106, -105, -104, -103, -102, -94, -93, -92, -91, -90, -89, -88, -87, -86, -78, -77, -76, -75, -74, -73, -72, -71, -70, -62, -61, -60, -59, -58, -57, -56, -55, -54, -46, -45, -44, -43, -42, -41, -40, -39, -38, -31, -30, -29, -28, -27, -26, -25, -24, -23, -22, -15, -14, -13, -12, -11, -10, -9, -8, -7, -6, -1, -60, 0, 31, 1, 0, 3, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, -1, -60, 0, -75, 17, 0, 2, 1, 2, 4, 4, 3, 4, 7, 5, 4, 4, 0, 1, 2, 119, 0, 1, 2, 3, 17, 4, 5, 33, 49, 6, 18, 65, 81, 7, 97, 113, 19, 34, 50, -127, 8, 20, 66, -111, -95, -79, -63, 9, 35, 51, 82, -16, 21, 98, 114, -47, 10, 22, 36, 52, -31, 37, -15, 23, 24, 25, 26, 38, 39, 40, 41, 42, 53, 54, 55, 56, 57, 58, 67, 68, 69, 70, 71, 72, 73, 74, 83, 84, 85, 86, 87, 88, 89, 90, 99, 100, 101, 102, 103, 104, 105, 106, 115, 116, 117, 118, 119, 120, 121, 122, -126, -125, -124, -123, -122, -121, -120, -119, -118, -110, -109, -108, -107, -106, -105, -104, -103, -102, -94, -93, -92, -91, -90, -89, -88, -87, -86, -78, -77, -76, -75, -74, -73, -72, -71, -70, -62, -61, -60, -59, -58, -57, -56, -55, -54, -46, -45, -44, -43, -42, -41, -40, -39, -38, -30, -29, -28, -27, -26, -25, -24, -23, -22, -14, -13, -12, -11, -10, -9, -8, -7, -6, -1, -38, 0, 12, 3, 1, 0, 2, 17, 3, 17, 0, 63, 0, -9, -6, 40, -94, -128, 63, -1, -39}; private final byte[] onePixelJpgExample = new byte[]{-1, -40, -1, -32, 0, 16, 74, 70, 73, 70, 0, 1, 2, 0, 0, 1, 0, 1, 0, 0, -1, -37, 0, 67, 0, 8, 6, 6, 7, 6, 5, 8, 7, 7, 7, 9, 9, 8, 10, 12, 20, 13, 12, 11, 11, 12, 25, 18, 19, 15, 20, 29, 26, 31, 30, 29, 26, 28, 28, 32, 36, 46, 39, 32, 34, 44, 35, 28, 28, 40, 55, 41, 44, 48, 49, 52, 52, 52, 31, 39, 57, 61, 56, 50, 60, 46, 51, 52, 50, -1, -37, 0, 67, 1, 9, 9, 9, 12, 11, 12, 24, 13, 13, 24, 50, 33, 28, 33, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, -1, -64, 0, 17, 8, 0, 1, 0, 1, 3, 1, 34, 0, 2, 17, 1, 3, 17, 1, -1, -60, 0, 31, 0, 0, 1, 5, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, -1, -60, 0, -75, 16, 0, 2, 1, 3, 3, 2, 4, 3, 5, 5, 4, 4, 0, 0, 1, 125, 1, 2, 3, 0, 4, 17, 5, 18, 33, 49, 65, 6, 19, 81, 97, 7, 34, 113, 20, 50, -127, -111, -95, 8, 35, 66, -79, -63, 21, 82, -47, -16, 36, 51, 98, 114, -126, 9, 10, 22, 23, 24, 25, 26, 37, 38, 39, 40, 41, 42, 52, 53, 54, 55, 56, 57, 58, 67, 68, 69, 70, 71, 72, 73, 74, 83, 84, 85, 86, 87, 88, 89, 90, 99, 100, 101, 102, 103, 104, 105, 106, 115, 116, 117, 118, 119, 120, 121, 122, -125, -124, -123, -122, -121, -120, -119, -118, -110, -109, -108, -107, -106, -105, -104, -103, -102, -94, -93, -92, -91, -90, -89, -88, -87, -86, -78, -77, -76, -75, -74, -73, -72, -71, -70, -62, -61, -60, -59, -58, -57, -56, -55, -54, -46, -45, -44, -43, -42, -41, -40, -39, -38, -31, -30, -29, -28, -27, -26, -25, -24, -23, -22, -15, -14, -13, -12, -11, -10, -9, -8, -7, -6, -1, -60, 0, 31, 1, 0, 3, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, -1, -60, 0, -75, 17, 0, 2, 1, 2, 4, 4, 3, 4, 7, 5, 4, 4, 0, 1, 2, 119, 0, 1, 2, 3, 17, 4, 5, 33, 49, 6, 18, 65, 81, 7, 97, 113, 19, 34, 50, -127, 8, 20, 66, -111, -95, -79, -63, 9, 35, 51, 82, -16, 21, 98, 114, -47, 10, 22, 36, 52, -31, 37, -15, 23, 24, 25, 26, 38, 39, 40, 41, 42, 53, 54, 55, 56, 57, 58, 67, 68, 69, 70, 71, 72, 73, 74, 83, 84, 85, 86, 87, 88, 89, 90, 99, 100, 101, 102, 103, 104, 105, 106, 115, 116, 117, 118, 119, 120, 121, 122, -126, -125, -124, -123, -122, -121, -120, -119, -118, -110, -109, -108, -107, -106, -105, -104, -103, -102, -94, -93, -92, -91, -90, -89, -88, -87, -86, -78, -77, -76, -75, -74, -73, -72, -71, -70, -62, -61, -60, -59, -58, -57, -56, -55, -54, -46, -45, -44, -43, -42, -41, -40, -39, -38, -30, -29, -28, -27, -26, -25, -24, -23, -22, -14, -13, -12, -11, -10, -9, -8, -7, -6, -1, -38, 0, 12, 3, 1, 0, 2, 17, 3, 17, 0, 63, 0, -9, -6, 40, -94, -128, 63, -1, -39};
private final int baseSize = 100; private final int baseSize = 100;
private final int halfSize = baseSize/2; private final int halfSize = baseSize / 2;
private final int doubleSize = baseSize*2; private final int doubleSize = baseSize * 2;
private final int minSize = 0; private final int minSize = 0;
@Before @Before
public void setUp() { public void setUp() {
jpgConverter = new ImageConverter(new ByteArrayInputStream(onePixelJpgExample),"jpg", new HashMap<String, Boolean>()); jpgConverter = new ImageConverter(new ByteArrayInputStream(onePixelJpgExample), "jpg",
pngConverter = new ImageConverter(new ByteArrayInputStream(onePixelPngExample),"png", new HashMap<String, Boolean>()); new HashMap<String, Boolean>());
pngConverter = new ImageConverter(new ByteArrayInputStream(onePixelPngExample), "png",
new HashMap<String, Boolean>());
assertNotNull(jpgConverter.getImage()); assertNotNull(jpgConverter.getImage());
assertNotNull(pngConverter.getImage()); assertNotNull(pngConverter.getImage());
} }
@Test @Test
public void testCalculateDimensions() { public void testCalculateDimensions() {
int[] dimensions; int[] dimensions;
@@ -49,18 +48,18 @@ public class ImageConverterTest {
dimensions = ImageConverter.calculateDimensions(minSize, minSize, halfSize, baseSize, halfSize, baseSize); dimensions = ImageConverter.calculateDimensions(minSize, minSize, halfSize, baseSize, halfSize, baseSize);
assertNull(dimensions); assertNull(dimensions);
} }
@Test @Test
public void testConversions() { public void testConversions() {
byte[] byteArray1 = ImageConverter.bufferedImageToByteArray(jpgConverter.getImage(), jpgConverter.getImageFormat()); byte[] byteArray1 = ImageConverter.bufferedImageToByteArray(jpgConverter.getImage(),
byte[] byteArray2 = jpgConverter.inputStreamToByteArray(jpgConverter.sourceImageToInputStream()); jpgConverter.getImageFormat());
byte[] byteArray2 = jpgConverter
.inputStreamToByteArray(jpgConverter.imageToInputStream(jpgConverter.getImage()));
assertArrayEquals(byteArray1, byteArray2); assertArrayEquals(byteArray1, byteArray2);
assertArrayEquals(byteArray1, onePixelJpgExample); assertArrayEquals(byteArray1, onePixelJpgExample);
byteArray1 = ImageConverter.bufferedImageToByteArray(pngConverter.getImage(), pngConverter.getImageFormat()); byteArray1 = ImageConverter.bufferedImageToByteArray(pngConverter.getImage(), pngConverter.getImageFormat());
byteArray2 = pngConverter.inputStreamToByteArray(pngConverter.sourceImageToInputStream()); byteArray2 = pngConverter.inputStreamToByteArray(pngConverter.imageToInputStream(jpgConverter.getImage()));
assertArrayEquals(byteArray1, byteArray2); assertArrayEquals(byteArray1, byteArray2);
assertArrayEquals(byteArray1, onePixelPngExample); assertArrayEquals(byteArray1, onePixelPngExample);
} }
} }