From 1b98e09bacb5e26416f3dca6a819c4dba132a2e4 Mon Sep 17 00:00:00 2001 From: Andrew Phillips Date: Sun, 25 Dec 2011 11:44:34 +0000 Subject: [PATCH] [issue 795] Added a @DataProvider and modified failing tests to selectively run under Java6/7 --- .../jclouds/http/functions/ParseSaxTest.java | 43 ++++++++++++++++++- .../java/org/jclouds/utils/TestUtils.java | 35 +++++++++++++++ 2 files changed, 76 insertions(+), 2 deletions(-) create mode 100644 core/src/test/java/org/jclouds/utils/TestUtils.java diff --git a/core/src/test/java/org/jclouds/http/functions/ParseSaxTest.java b/core/src/test/java/org/jclouds/http/functions/ParseSaxTest.java index 61bf1dd712..4d9456ff8f 100644 --- a/core/src/test/java/org/jclouds/http/functions/ParseSaxTest.java +++ b/core/src/test/java/org/jclouds/http/functions/ParseSaxTest.java @@ -22,6 +22,8 @@ import static org.easymock.EasyMock.expect; import static org.easymock.classextension.EasyMock.createMock; import static org.easymock.classextension.EasyMock.replay; import static org.easymock.classextension.EasyMock.verify; +import static org.jclouds.utils.TestUtils.NO_INVOCATIONS; +import static org.jclouds.utils.TestUtils.SINGLE_NO_ARG_INVOCATION; import static org.testng.Assert.assertEquals; import java.io.IOException; @@ -31,6 +33,8 @@ import java.util.concurrent.TimeoutException; import org.jclouds.http.HttpRequest; import org.jclouds.http.HttpResponse; +import org.jclouds.utils.TestUtils; +import org.testng.annotations.DataProvider; import org.testng.annotations.Test; import org.xml.sax.Locator; import org.xml.sax.SAXParseException; @@ -53,7 +57,17 @@ public class ParseSaxTest extends BaseHandlerTest { ParseSax createParser() { return factory.create(injector.getInstance(TestHandler.class)); } + + @DataProvider + public Object[][] runUnderJava7() { + return (TestUtils.isJava7() ? SINGLE_NO_ARG_INVOCATION : NO_INVOCATIONS); + } + @DataProvider + public Object[][] ignoreUnderJava7() { + return (TestUtils.isJava7() ? NO_INVOCATIONS : SINGLE_NO_ARG_INVOCATION); + } + @Test public void testAddDetailsAndPropagateOkWhenRequestWithNoDataAndRuntimeExceptionThrowsOriginalException() throws ExecutionException, InterruptedException, TimeoutException, IOException { @@ -99,7 +113,7 @@ public class ParseSaxTest extends BaseHandlerTest { assertEquals(e.getCause(), input); } } - + @Test public void testAddDetailsAndPropagateOkWithValidRequestResponse() throws ExecutionException, InterruptedException, TimeoutException, IOException { @@ -118,7 +132,7 @@ public class ParseSaxTest extends BaseHandlerTest { } } - @Test + @Test(dataProvider = "ignoreUnderJava7", description = "see http://code.google.com/p/jclouds/issues/detail?id=795") public void testAddDetailsAndPropagateOkWithValidRequestResponseWithSAXParseException() throws ExecutionException, InterruptedException, TimeoutException, IOException { @@ -144,4 +158,29 @@ public class ParseSaxTest extends BaseHandlerTest { } } + @Test(dataProvider = "runUnderJava7", description = "see http://code.google.com/p/jclouds/issues/detail?id=795") + public void testAddDetailsAndPropagateOkWithValidRequestResponseWithSAXParseException_java7() throws ExecutionException, + InterruptedException, TimeoutException, IOException { + + ParseSax parser = createParser(); + HttpRequest request = new HttpRequest("GET", URI.create("http://foohost")); + HttpResponse response = new HttpResponse(304, "Not Modified", null); + Locator locator = createMock(Locator.class); + expect(locator.getColumnNumber()).andReturn(1); + expect(locator.getLineNumber()).andReturn(1); + expect(locator.getPublicId()).andReturn("publicId"); + expect(locator.getSystemId()).andReturn("systemId"); + replay(locator); + Exception input = new SAXParseException("foo", locator); + verify(locator); + + try { + parser.setContext(request); + parser.addDetailsAndPropagate(response, input); + } catch (RuntimeException e) { + assertEquals(e.getMessage(), + "request: GET http://foohost HTTP/1.1; response: HTTP/1.1 304 Not Modified; error at 1:1 in document systemId; cause: org.xml.sax.SAXParseExceptionpublicId: publicId; systemId: systemId; lineNumber: 1; columnNumber: 1; foo"); + assertEquals(e.getCause(), input); + } + } } \ No newline at end of file diff --git a/core/src/test/java/org/jclouds/utils/TestUtils.java b/core/src/test/java/org/jclouds/utils/TestUtils.java new file mode 100644 index 0000000000..a3c1d4dbc4 --- /dev/null +++ b/core/src/test/java/org/jclouds/utils/TestUtils.java @@ -0,0 +1,35 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds 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.jclouds.utils; + +/** + * Utility class for test + * + * @author Andrew Phillips + * + */ +public class TestUtils { + public static final Object[][] NO_INVOCATIONS = new Object[0][0]; + public static final Object[][] SINGLE_NO_ARG_INVOCATION = new Object[][] { new Object[0] }; + + public static boolean isJava7() { + System.out.println(System.getProperty("java.version", "None??")); + return System.getProperty("java.version", "").contains("1.7."); + } +}