| /* |
| * Licensed to the Apache Software Foundation (ASF) under one or more |
| * contributor license agreements. See the NOTICE file distributed with |
| * this work for additional information regarding copyright ownership. |
| * The ASF licenses this file to You under the Apache License, Version 2.0 |
| * (the "License"); you may not use this file except in compliance with |
| * the License. You may obtain a copy of the License at |
| * |
| * http://www.apache.org/licenses/LICENSE-2.0 |
| * |
| * Unless required by applicable law or agreed to in writing, software |
| * distributed under the License is distributed on an "AS IS" BASIS, |
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| * See the License for the specific language governing permissions and |
| * limitations under the License. |
| */ |
| package org.apache.sling.thumbnails.internal.transformers; |
| |
| import static org.junit.Assert.assertEquals; |
| import static org.junit.Assert.assertNotEquals; |
| import static org.junit.Assert.assertNotNull; |
| |
| import java.io.ByteArrayOutputStream; |
| import java.io.IOException; |
| import java.io.InputStream; |
| import java.util.HashMap; |
| import java.util.Map; |
| |
| import org.apache.sling.thumbnails.internal.models.TransformationHandlerConfigImpl; |
| import org.apache.sling.thumbnails.TransformationHandlerConfig; |
| import org.junit.Before; |
| import org.junit.Test; |
| |
| public class RotateHandlerTest { |
| |
| private InputStream inputStream; |
| private ByteArrayOutputStream outputStream; |
| private RotateHandler spinner; |
| |
| @Before |
| public void init() { |
| inputStream = getClass().getClassLoader().getResourceAsStream("apache.png"); |
| outputStream = new ByteArrayOutputStream(); |
| spinner = new RotateHandler(); |
| } |
| |
| @Test |
| public void testResourceType() throws IOException { |
| assertEquals("sling/thumbnails/transformers/rotate", spinner.getResourceType()); |
| } |
| |
| @Test |
| public void testRotate() throws IOException { |
| |
| Map<String, Object> properties = new HashMap<>(); |
| properties.put(RotateHandler.DEGREES, 200); |
| |
| TransformationHandlerConfig config = new TransformationHandlerConfigImpl("/conf", properties); |
| spinner.handle(inputStream, outputStream, config); |
| assertNotEquals(0, outputStream.toByteArray().length); |
| } |
| |
| @Test |
| public void testNoDegrees() throws IOException { |
| Map<String, Object> properties = new HashMap<>(); |
| |
| TransformationHandlerConfig config = new TransformationHandlerConfigImpl("/conf", properties); |
| spinner.handle(inputStream, outputStream, config); |
| assertNotNull(outputStream.toByteArray()); |
| } |
| |
| @Test |
| public void testNegativeDegrees() throws IOException { |
| Map<String, Object> properties = new HashMap<>(); |
| properties.put(RotateHandler.DEGREES, -200); |
| |
| TransformationHandlerConfig config = new TransformationHandlerConfigImpl("/conf", properties); |
| spinner.handle(inputStream, outputStream, config); |
| assertNotNull(outputStream.toByteArray()); |
| } |
| |
| @Test |
| public void testAbsurdlyHighDegrees() throws IOException { |
| Map<String, Object> properties = new HashMap<>(); |
| properties.put(RotateHandler.DEGREES, Integer.MAX_VALUE); |
| |
| TransformationHandlerConfig config = new TransformationHandlerConfigImpl("/conf", properties); |
| spinner.handle(inputStream, outputStream, config); |
| assertNotNull(outputStream.toByteArray()); |
| } |
| |
| } |