axis-java-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ntha...@apache.org
Subject svn commit: r673180 - in /webservices/axis2/trunk/java/modules/jaxws: src/org/apache/axis2/jaxws/utility/AttachmentUtils.java test-resources/image/image1.jpeg test-resources/image/image2.jpeg test/org/apache/axis2/jaxws/utility/AttachmentUtilityTests.java
Date Tue, 01 Jul 2008 19:06:24 GMT
Author: nthaker
Date: Tue Jul  1 12:06:24 2008
New Revision: 673180

URL: http://svn.apache.org/viewvc?rev=673180&view=rev
Log:
AXIS2-3884

Added:
    webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/utility/AttachmentUtils.java
    webservices/axis2/trunk/java/modules/jaxws/test-resources/image/image1.jpeg   (with props)
    webservices/axis2/trunk/java/modules/jaxws/test-resources/image/image2.jpeg   (with props)
    webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/utility/AttachmentUtilityTests.java

Added: webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/utility/AttachmentUtils.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/utility/AttachmentUtils.java?rev=673180&view=auto
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/utility/AttachmentUtils.java
(added)
+++ webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/utility/AttachmentUtils.java
Tue Jul  1 12:06:24 2008
@@ -0,0 +1,60 @@
+package org.apache.axis2.jaxws.utility;
+
+/*
+ * 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.
+ */
+
+import java.awt.Image;
+import java.awt.image.BufferedImage;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+public class AttachmentUtils {
+private static final Log log = LogFactory.getLog(AttachmentUtils.class);
+	
+	public static boolean compareImages(Image img1, Image img2){
+		if(img1 == null && img2==null){
+			if(log.isDebugEnabled()){
+				log.debug("Both Image Objects are null, cannot compare Images returning false");
+			}
+			return false;
+		}
+		int h1 = img1.getHeight(null);
+		int h2 = img2.getHeight(null);
+		int w1 = img1.getWidth(null);
+		int w2 = img1.getWidth(null);
+		if(h1 != h2 || w1 != w2){
+			return false;
+		}
+		if(img1 instanceof BufferedImage && img2 instanceof BufferedImage){
+			BufferedImage bi1 = (BufferedImage)img1;
+			BufferedImage bi2 = (BufferedImage)img2;
+			for(int h=0;h<h1;++h){
+				for(int w=0; w<w1; ++w){
+					int Img1Pixel =bi1.getRGB(w, h);
+					int Img2Pixel =bi2.getRGB(w, h);
+					if(Img1Pixel!=Img2Pixel){
+						return false;
+					}
+				}
+			}
+		}
+		return true;		
+	}
+}

Added: webservices/axis2/trunk/java/modules/jaxws/test-resources/image/image1.jpeg
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws/test-resources/image/image1.jpeg?rev=673180&view=auto
==============================================================================
Binary file - no diff available.

Propchange: webservices/axis2/trunk/java/modules/jaxws/test-resources/image/image1.jpeg
------------------------------------------------------------------------------
    svn:mime-type = application/octet-stream

Added: webservices/axis2/trunk/java/modules/jaxws/test-resources/image/image2.jpeg
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws/test-resources/image/image2.jpeg?rev=673180&view=auto
==============================================================================
Binary file - no diff available.

Propchange: webservices/axis2/trunk/java/modules/jaxws/test-resources/image/image2.jpeg
------------------------------------------------------------------------------
    svn:mime-type = application/octet-stream

Added: webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/utility/AttachmentUtilityTests.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/utility/AttachmentUtilityTests.java?rev=673180&view=auto
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/utility/AttachmentUtilityTests.java
(added)
+++ webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/utility/AttachmentUtilityTests.java
Tue Jul  1 12:06:24 2008
@@ -0,0 +1,73 @@
+/*
+ * 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.axis2.jaxws.utility;
+
+import java.awt.Image;
+import java.io.File;
+
+import javax.imageio.ImageIO;
+
+import junit.framework.TestCase;
+
+public class AttachmentUtilityTests extends TestCase {
+	public void testCompareDifferentImages(){
+		try{
+			String img1Path = "/test-resources/image/image1.jpeg";
+			String img2Path = "/test-resources/image/image2.jpeg";
+			
+			String img1FilePath = getAbsoluteLocation()+img1Path;
+			String img2FilePath = getAbsoluteLocation()+img2Path;
+			
+			File img1File = new File(img1FilePath);
+			File img2File = new File(img2FilePath);
+			Image img1=ImageIO.read(img1File) ;
+			Image img2= ImageIO.read(img2File);
+			assertFalse(AttachmentUtils.compareImages(img1, img2));
+			System.out.println("Image Compared successfully");
+		}catch(Exception e){
+			System.out.println("Image Compare Failed");
+			e.printStackTrace();
+			fail();
+		}
+	}
+	public void testCompareSameImages(){
+		try{
+			String img1Path = "/test-resources/image/image1.jpeg";
+			String img1FilePath = getAbsoluteLocation()+img1Path;
+			
+			File img1File = new File(img1FilePath);
+			File img2File = new File(img1FilePath);
+			
+			Image img1=ImageIO.read(img1File) ;
+			Image img2= ImageIO.read(img2File);
+			
+			assertTrue(AttachmentUtils.compareImages(img1, img1));
+			System.out.println("Image Compared successfully");
+		}catch(Exception e){
+			e.printStackTrace();
+			System.out.println("Image Compare Failed");
+			fail();
+		}
+	}
+	private String getAbsoluteLocation(){
+		
+		return new File("").getAbsolutePath();
+	}
+}



Mime
View raw message