List of usage examples for java.lang IllegalArgumentException getClass
@HotSpotIntrinsicCandidate public final native Class<?> getClass();
From source file:jp.terasoluna.fw.util.ConvertUtilTest.java
/** * testToListOfMap10() <br>/*from w w w.j av a 2 s. c om*/ * <br> * () <br> * G <br> * <br> * () obj:JavaBean<br> * A="value00"<br> * () PropertyUtils#describe??: NoSuchMethodException PropertyUtilsBean??NoSuchMethodException<br> * <br> * () :IllegalArgumentException<br> * ??NoSuchMethodException<br> * <br> * PropertyUtils#descrive?NoSuchMethodException????? <br> * @throws Exception ????? */ @Test public void testToListOfMap10() throws Exception { // ?? List<ConvertUtil_Stub01> obj = new ArrayList<ConvertUtil_Stub01>(); ConvertUtil_Stub01 bean = new ConvertUtil_Stub01(); bean.setA("value00"); obj.add(bean); BeanUtilsBean beanUtilsBean = BeanUtilsBean.getInstance(); ReflectionTestUtils.setField(beanUtilsBean, "propertyUtilsBean", new ConvertUtil_PropertyUtilsBeanStub02()); try { // ConvertUtil.toListOfMap(obj); fail(); } catch (IllegalArgumentException e) { // assertEquals(IllegalArgumentException.class.getName(), e.getClass().getName()); assertTrue(e.getCause() instanceof NoSuchMethodException); } }
From source file:jp.terasoluna.fw.util.ConvertUtilTest.java
/** * testToList10() <br>/*from ww w . j a v a 2s . c o m*/ * <br> * () <br> * G <br> * <br> * () obj:????Object[]<br> * *?0:"foo"<br> * *?2:Thread<br> * *?3:"baz"<br> * () elementClass:String.class<br> * <br> * () :IllegalArgumentException<br> * ?: "Unable to cast '" + Thread??? + "' to '" + elementClass??? + "'"<br> * ??:ClassCastException<br> * ???: "Unable to cast '" + Thread??? + "' to '" + elementClass??? + "'"<br> * <br> * obj???elementClass?????????????? ?????????IllegalArgumentException???? ?? <br> * @throws Exception ????? */ @Test public void testToList10() throws Exception { // ?? Object[] obj = new Object[3]; obj[0] = "foo"; obj[1] = new Thread(); obj[2] = "baz"; // try { ConvertUtil.toList(obj, String.class); fail("IllegalArgumentException???????"); } catch (IllegalArgumentException e) { // assertEquals(IllegalArgumentException.class.getName(), e.getClass().getName()); assertEquals("Unable to cast '" + Thread.class.getName() + "' to '" + String.class.getName() + "'", e.getMessage()); assertEquals(ClassCastException.class.getName(), e.getCause().getClass().getName()); assertEquals("Unable to cast '" + Thread.class.getName() + "' to '" + String.class.getName() + "'", e.getCause().getMessage()); } }
From source file:jp.terasoluna.fw.util.ConvertUtilTest.java
/** * testToList14() <br>// www . j a va 2 s . c o m * <br> * () <br> * G <br> * <br> * () obj:????Collection<br> * *?0:"foo"<br> * *?2:Thread<br> * *?3:"baz"<br> * () elementClass:String.class<br> * <br> * () :IllegalArgumentException<br> * ?: "Unable to cast '" + Thread??? + "' to '" + elementClass??? + "'"<br> * ??:ClassCastException<br> * ???: "Unable to cast '" + Thread??? + "' to '" + elementClass??? + "'"<br> * <br> * obj?Collection?elementClass?????????? ?????????????IllegalArgumentException???? ?? <br> * @throws Exception ????? */ @Test public void testToList14() throws Exception { // ?? Object[] obj = new Object[3]; obj[0] = "foo"; obj[1] = new Thread(); obj[2] = "baz"; // try { ConvertUtil.toList(obj, String.class); fail("IllegalArgumentException???????"); } catch (IllegalArgumentException e) { // assertEquals(IllegalArgumentException.class.getName(), e.getClass().getName()); assertEquals("Unable to cast '" + Thread.class.getName() + "' to '" + String.class.getName() + "'", e.getMessage()); assertEquals(ClassCastException.class.getName(), e.getCause().getClass().getName()); assertEquals("Unable to cast '" + Thread.class.getName() + "' to '" + String.class.getName() + "'", e.getCause().getMessage()); } }
From source file:net.pms.network.RequestHandler.java
@Override public void run() { Request request = null;/*from w w w. j a v a 2s . co m*/ StartStopListenerDelegate startStopListenerDelegate = new StartStopListenerDelegate( socket.getInetAddress().getHostAddress()); try { int receivedContentLength = -1; String userAgentString = null; ArrayList<String> identifiers = new ArrayList<>(); RendererConfiguration renderer = null; InetSocketAddress remoteAddress = (InetSocketAddress) socket.getRemoteSocketAddress(); InetAddress ia = remoteAddress.getAddress(); boolean isSelf = ia.getHostAddress().equals(PMS.get().getServer().getHost()); // Apply the IP filter if (filterIp(ia)) { throw new IOException("Access denied for address " + ia + " based on IP filter"); } LOGGER.trace("Opened request handler on socket " + socket); PMS.get().getRegistry().disableGoToSleep(); // The handler makes a couple of attempts to recognize a renderer from its requests. // IP address matches from previous requests are preferred, when that fails request // header matches are attempted and if those fail as well we're stuck with the // default renderer. // Attempt 1: try to recognize the renderer by its socket address from previous requests renderer = RendererConfiguration.getRendererConfigurationBySocketAddress(ia); // If the renderer exists but isn't marked as loaded it means it's unrecognized // by upnp and we still need to attempt http recognition here. boolean unrecognized = renderer == null || !renderer.loaded; RendererConfiguration.SortedHeaderMap sortedHeaders = unrecognized ? new RendererConfiguration.SortedHeaderMap() : null; // Gather all the headers ArrayList<String> headerLines = new ArrayList<>(); String line = br.readLine(); while (line != null && line.length() > 0) { headerLines.add(line); if (unrecognized) { sortedHeaders.put(line); } line = br.readLine(); } if (unrecognized) { // Attempt 2: try to recognize the renderer by matching headers renderer = RendererConfiguration.getRendererConfigurationByHeaders(sortedHeaders, ia); } for (String headerLine : headerLines) { LOGGER.trace("Received on socket: " + headerLine); // The request object is created inside the while loop. if (request != null && request.getMediaRenderer() == null && renderer != null) { request.setMediaRenderer(renderer); } if (headerLine.toUpperCase().startsWith("USER-AGENT")) { // Is the request from our own Cling service, i.e. self-originating? if (isSelf && headerLine.contains("UMS/")) { LOGGER.trace( "Ignoring self-originating request from " + ia + ":" + remoteAddress.getPort()); return; } userAgentString = headerLine.substring(headerLine.indexOf(':') + 1).trim(); } try { StringTokenizer s = new StringTokenizer(headerLine); String temp = s.nextToken(); if (temp.equals("SUBSCRIBE") || temp.equals("GET") || temp.equals("POST") || temp.equals("HEAD")) { request = new Request(temp, s.nextToken().substring(1)); if (s.hasMoreTokens() && s.nextToken().equals("HTTP/1.0")) { request.setHttp10(true); } } else if (request != null && temp.toUpperCase().equals("CALLBACK:")) { request.setSoapaction(s.nextToken()); } else if (request != null && temp.toUpperCase().equals("SOAPACTION:")) { request.setSoapaction(s.nextToken()); } else if (headerLine.toUpperCase().contains("CONTENT-LENGTH:")) { receivedContentLength = Integer.parseInt( headerLine.substring(headerLine.toUpperCase().indexOf("CONTENT-LENGTH: ") + 16)); } else if (headerLine.toUpperCase().contains("RANGE: BYTES=")) { String nums = headerLine.substring(headerLine.toUpperCase().indexOf("RANGE: BYTES=") + 13) .trim(); StringTokenizer st = new StringTokenizer(nums, "-"); if (!nums.startsWith("-")) { request.setLowRange(Long.parseLong(st.nextToken())); } if (!nums.startsWith("-") && !nums.endsWith("-")) { request.setHighRange(Long.parseLong(st.nextToken())); } else { request.setHighRange(-1); } } else if (headerLine.toLowerCase().contains("transfermode.dlna.org:")) { request.setTransferMode(headerLine .substring(headerLine.toLowerCase().indexOf("transfermode.dlna.org:") + 22).trim()); } else if (headerLine.toLowerCase().contains("getcontentfeatures.dlna.org:")) { request.setContentFeatures(headerLine .substring(headerLine.toLowerCase().indexOf("getcontentfeatures.dlna.org:") + 28) .trim()); } else if (headerLine.toUpperCase().contains("TIMESEEKRANGE.DLNA.ORG: NPT=")) { // firmware 2.50+ String timeseek = headerLine .substring(headerLine.toUpperCase().indexOf("TIMESEEKRANGE.DLNA.ORG: NPT=") + 28); if (timeseek.endsWith("-")) { timeseek = timeseek.substring(0, timeseek.length() - 1); } else if (timeseek.indexOf('-') > -1) { timeseek = timeseek.substring(0, timeseek.indexOf('-')); } request.setTimeseek(convertStringToTime(timeseek)); } else if (headerLine.toUpperCase().contains("TIMESEEKRANGE.DLNA.ORG : NPT=")) { // firmware 2.40 String timeseek = headerLine .substring(headerLine.toUpperCase().indexOf("TIMESEEKRANGE.DLNA.ORG : NPT=") + 29); if (timeseek.endsWith("-")) { timeseek = timeseek.substring(0, timeseek.length() - 1); } else if (timeseek.indexOf('-') > -1) { timeseek = timeseek.substring(0, timeseek.indexOf('-')); } request.setTimeseek(convertStringToTime(timeseek)); } else { /* * If we made it to here, none of the previous header checks matched. * Unknown headers make interesting logging info when we cannot recognize * the media renderer, so keep track of the truly unknown ones. */ boolean isKnown = false; // Try to match possible known headers. String lowerCaseHeaderLine = headerLine.toLowerCase(); for (String knownHeaderString : KNOWN_HEADERS) { if (lowerCaseHeaderLine.startsWith(knownHeaderString.toLowerCase())) { isKnown = true; break; } } // It may be unusual but already known if (renderer != null) { String additionalHeader = renderer.getUserAgentAdditionalHttpHeader(); if (StringUtils.isNotBlank(additionalHeader) && lowerCaseHeaderLine.startsWith(additionalHeader)) { isKnown = true; } } if (!isKnown) { // Truly unknown header, therefore interesting. Save for later use. identifiers.add(headerLine); } } } catch (IllegalArgumentException e) { LOGGER.error("Error in parsing HTTP headers", e); } } if (request != null) { // Still no media renderer recognized? if (renderer == null) { // Attempt 3: Not really an attempt; all other attempts to recognize // the renderer have failed. The only option left is to assume the // default renderer. renderer = RendererConfiguration.resolve(ia, null); request.setMediaRenderer(renderer); if (renderer != null) { LOGGER.trace("Using default media renderer: " + renderer.getConfName()); if (userAgentString != null && !userAgentString.equals("FDSSDP")) { // We have found an unknown renderer identifiers.add(0, "User-Agent: " + userAgentString); renderer.setIdentifiers(identifiers); LOGGER.info("Media renderer was not recognized. Possible identifying HTTP headers:" + StringUtils.join(identifiers, ", ")); } } else { // If RendererConfiguration.resolve() didn't return the default renderer // it means we know via upnp that it's not really a renderer. return; } } else { if (userAgentString != null) { LOGGER.trace("HTTP User-Agent: " + userAgentString); } LOGGER.trace("Recognized media renderer: " + renderer.getRendererName()); } } if (receivedContentLength > 0) { char buf[] = new char[receivedContentLength]; br.read(buf); if (request != null) { request.setTextContent(new String(buf)); } } if (request != null) { LOGGER.trace("HTTP: " + request.getArgument() + " / " + request.getLowRange() + "-" + request.getHighRange()); } if (request != null) { request.answer(output, startStopListenerDelegate); } if (request != null && request.getInputStream() != null) { request.getInputStream().close(); } } catch (IOException e) { LOGGER.trace("Unexpected IO error: " + e.getClass().getName() + ": " + e.getMessage()); if (request != null && request.getInputStream() != null) { try { LOGGER.trace("Closing input stream: " + request.getInputStream()); request.getInputStream().close(); } catch (IOException e1) { LOGGER.error("Error closing input stream", e1); } } } finally { try { PMS.get().getRegistry().reenableGoToSleep(); output.close(); br.close(); socket.close(); } catch (IOException e) { LOGGER.error("Error closing connection: ", e); } startStopListenerDelegate.stop(); LOGGER.trace("Close connection"); } }
From source file:org.opencastproject.util.ZipUtilTest.java
/** Check the behavior with bad arguments for the unzip signature File, File */ @Test//from w w w . j ava2s. co m public void badInputUnzipFileFile() throws Exception { File destFile = new File(destDir, "badInputFileFile"); try { // Null input file, correct destination file try { ZipUtil.unzip((File) null, destFile); logger.error("Unzip should fail when input File is null"); Assert.fail("Unzip should fail when input File is null"); } catch (IllegalArgumentException e) { logger.debug("Detecting null input File (File, File): OK"); } // Non-existing input file, correct destination file try { ZipUtil.unzip(dummieFile, destFile); logger.error("Unzip should fail when input File doesn't exist"); Assert.fail("Unzip should fail when input File doesn't exist"); } catch (FileNotFoundException e) { logger.debug("Detecting non-existing input File (File, File): OK"); } // Correct input filename, null destination filename try { ZipUtil.unzip(sampleZip, (File) null); logger.error("Unzip should fail when destination File is null"); Assert.fail("Unzip should fail when destination File is null"); } catch (IllegalArgumentException e) { logger.debug("Detecting null destination File (File, File): OK"); } // Invalid input file (using a regular file as input), correct destination file try { ZipUtil.unzip(srcFile, destFile); logger.error("Unzip should fail when the input File does not represent a zip file"); Assert.fail("Unzip should fail when the input File does not represent a zip file"); } catch (IllegalArgumentException e) { logger.debug("Detecting input File not representing a valid zip file (File, File): OK"); } // Correct input file, invalid destination file (some existing regular file rather than a dir) try { ZipUtil.unzip(sampleZip, srcFile); logger.error("Unzip should fail when the destination File does not represent a directory"); Assert.fail("Unzip should fail when the destination File does not represent a directory"); } catch (IllegalArgumentException e) { logger.debug("Detecting destination File not representing a directory (File, File): OK"); } } catch (Exception e) { logger.error("Another exception was expected, but got {} instead: {}", e.getClass().getName(), e.getMessage()); Assert.fail("Another exception was expected, but got " + e.getClass().getName() + "instead: " + e.getMessage()); } }
From source file:org.opencastproject.util.ZipUtilTest.java
/** Check the behavior with bad arguments for the unzip signature String, File */ @Test// w w w .jav a 2s. c o m public void badInputUnzipStrFile() throws Exception { File destFile = new File(destDir, "badInputStrFile"); try { // Null input filename, correct destination file try { ZipUtil.unzip((String) null, destFile); logger.error("Unzip should fail when input filename is null"); Assert.fail("Unzip should fail when input filename is null"); } catch (IllegalArgumentException e) { logger.debug("Detecting null input filename (String, File): OK"); } // Empty input filename, correct destination file try { ZipUtil.unzip("", destFile); logger.error("Unzip should fail when input filename is empty"); Assert.fail("Unzip should fail when input filename is empty"); } catch (IllegalArgumentException e) { logger.debug("Detecting empty input filename (String, File): OK"); } // Non-existing input filename, correct destination file try { ZipUtil.unzip(dummieFile.getCanonicalPath(), destFile); logger.error("Unzip should fail when the input filename doesn't exists"); Assert.fail("Unzip should fail when the input filename doesn't exists"); } catch (FileNotFoundException e) { logger.debug("Detecting existing input filename (String, File): OK"); } // Correct input filename, null destination file try { ZipUtil.unzip(sampleZip.getCanonicalPath(), (File) null); logger.error("Unzip should fail when destination filename is null"); Assert.fail("Unzip should fail when destination filename is null"); } catch (IllegalArgumentException e) { logger.debug("Detecting null destination filename (String, File): OK"); } // Invalid input filename (using a regular file as input), correct destination file try { ZipUtil.unzip(srcFile.getCanonicalPath(), destFile); logger.error("Unzip should fail when the input filename does not represent a zip file"); Assert.fail("Unzip should fail when the input filename does not represent a zip file"); } catch (IllegalArgumentException e) { logger.debug("Detecting input filename not representing a valid zip file (String, File): OK"); } // Correct input filename, invalid destination file (some existing regular file rather than a dir) try { ZipUtil.unzip(sampleZip.getCanonicalPath(), srcFile); logger.error("Unzip should fail when the destination File does not represent a directory"); Assert.fail("Unzip should fail when the destination File does not represent a directory"); } catch (IllegalArgumentException e) { logger.debug("Detecting destination File not representing a directory (String, File): OK"); } } catch (Exception e) { logger.error("Another exception was expected, but got {} instead: {}", e.getClass().getName(), e.getMessage()); Assert.fail("Another exception was expected, but got " + e.getClass().getName() + "instead: " + e.getMessage()); } }
From source file:org.opencastproject.util.ZipUtilTest.java
/** Check the behavior with bad arguments for the unzip signature File, String */ @Test//ww w.j a v a 2 s. c o m public void badInputUnzipFileStr() throws Exception { File destFile = new File(destDir, "badInputFileStr"); try { // Null input file, correct destination filename try { ZipUtil.unzip((File) null, destFile.getCanonicalPath()); logger.error("Unzip should fail when input File is null"); Assert.fail("Unzip should fail when input File is null"); } catch (IllegalArgumentException e) { logger.debug("Detecting null input File (File, String): OK"); } // Non-existing input file, correct destination filename try { ZipUtil.unzip(dummieFile, destFile.getCanonicalPath()); logger.error("Unzip should fail when input File doesn't exist"); Assert.fail("Unzip should fail when input File doesn't exist"); } catch (FileNotFoundException e) { logger.debug("Detecting non-existing input File (File, String): OK"); } // Correct input file, null destination filename try { ZipUtil.unzip(sampleZip, (String) null); logger.error("Unzip should fail when destination filename is null"); Assert.fail("Unzip should fail when destination filename is null"); } catch (IllegalArgumentException e) { logger.debug("Detecting null destination filename (File, String): OK"); } // Correct input file, empty destination filename try { ZipUtil.unzip(sampleZip.getCanonicalPath(), ""); logger.error("Unzip should fail when destination filename is empty"); Assert.fail("Unzip should fail when destination filename is empty"); } catch (IllegalArgumentException e) { logger.debug("Detecting empty destination filename (File, String): OK"); } // Invalid input filename (using a regular file as input), correct destination filename try { ZipUtil.unzip(srcFile, destFile.getCanonicalPath()); logger.error("Unzip should fail when the input File does not represent a zip file"); Assert.fail("Unzip should fail when the input File does not represent a zip file"); } catch (IllegalArgumentException e) { logger.debug("Detecting input File not representing a valid zip file (File, String): OK"); } // Correct input file, invalid destination filename (some existing regular file rather than a dir) try { ZipUtil.unzip(sampleZip, srcFile.getCanonicalPath()); logger.error("Unzip should fail when the destination filename does not represent a directory"); Assert.fail("Unzip should fail when the destination filename does not represent a directory"); } catch (IllegalArgumentException e) { logger.debug("Detecting destination filename not representing a directory (File, String): OK"); } } catch (Exception e) { logger.error("Another exception was expected, but got {} instead: {}", e.getClass().getName(), e.getMessage()); Assert.fail("Another exception was expected, but got " + e.getClass().getName() + "instead: " + e.getMessage()); } }
From source file:org.opencastproject.util.ZipUtilTest.java
/** Check the behavior before bad arguments for the signature File[], File */ @Test/* w w w. j a va 2s . com*/ public void badInputZipFileFile() throws Exception { File destFile = new File(destDir, "badInputFileFile.zip"); try { // Null File array, correct destination File try { ZipUtil.zip((File[]) null, destFile, true, ZipUtil.NO_COMPRESSION); logger.error("Zip should fail when input File array is null"); Assert.fail("Zip should fail when input File array is null"); } catch (IllegalArgumentException e) { logger.debug("Detecting null input File array (File, File): OK"); } // Null some of the input files, correct destination file try { ZipUtil.zip(new File[] { srcFile, null, nestedSrcFile }, destFile, true, ZipUtil.NO_COMPRESSION); logger.error("Zip should fail when any input file is null"); Assert.fail("Zip should fail when any input file is null"); } catch (IllegalArgumentException e) { logger.debug("Detecting null input filename (File, File): OK"); } // Non-existing some of the input files, correct destination file try { ZipUtil.zip(new File[] { srcFile, dummieFile, nestedSrcFile }, destFile, true, ZipUtil.NO_COMPRESSION); logger.error("Zip should fail when any input file does not exist"); Assert.fail("Zip should fail when any input file does not exist"); } catch (FileNotFoundException e) { logger.debug("Detecting non-existing input filename (File, File): OK"); } // Correct input Files, null destination File try { ZipUtil.zip(new File[] { srcFile, nestedSrcFile }, (File) null, true, ZipUtil.NO_COMPRESSION); logger.error("Zip should fail when destination File is null"); Assert.fail("Zip should fail when destination File is null"); } catch (IllegalArgumentException e) { logger.debug("Detecting null destination File (File, File): OK"); } // Correct input Files, existing destination File try { ZipUtil.zip(new File[] { srcFile, nestedSrcFile }, sampleZip, true, ZipUtil.NO_COMPRESSION); logger.error("Zip should fail when destination File already exists"); Assert.fail("Zip should fail when destination File already exists"); } catch (IllegalArgumentException e) { logger.debug("Detecting existing destination File (File, File): OK"); } // Invalid name for the zip file try { ZipUtil.zip(new File[] { srcFile, nestedSrcFile }, dummieFile, true, ZipUtil.NO_COMPRESSION); logger.error("Zip should fail when the destination File does not represent a zip file"); Assert.fail("Zip should fail when the destination File does not represent a zip file"); } catch (IllegalArgumentException e) { logger.debug("Detecting destination File not representing a valid zip file (File, File): OK"); } } catch (Exception e) { logger.error("Another exception was expected, but got {} instead: {}", e.getClass().getName(), e.getMessage()); Assert.fail("Another exception was expected, but got " + e.getClass().getName() + " instead: " + e.getMessage()); } }
From source file:org.opencastproject.util.ZipUtilTest.java
/** Check the behavior with bad arguments for the zip signature String[], File */ @Test//from ww w .j a va2 s.co m public void badInputZipStrFile() throws Exception { File destFile = new File(destDir, "badInputStrFile.zip"); try { // Null input filenames array, correct destination file try { ZipUtil.zip((String[]) null, destFile, true, 0); logger.error("Zip should fail when input String array is null"); Assert.fail("Zip should fail when input String array is null"); } catch (IllegalArgumentException e) { logger.debug("Detecting null input File array (String, File): OK"); } // Null some of the input filenames, correct destination file try { ZipUtil.zip(new String[] { srcFile.getCanonicalPath(), null, nestedSrcFile.getCanonicalPath() }, destFile, true, ZipUtil.NO_COMPRESSION); logger.error("Zip should fail when any input filename is null"); Assert.fail("Zip should fail when any input filename is null"); } catch (IllegalArgumentException e) { logger.debug("Detecting null input filename (String, File): OK"); } // Non-existing some of the input filenames, correct destination file try { ZipUtil.zip(new String[] { srcFile.getCanonicalPath(), dummieFile.getCanonicalPath(), nestedSrcFile.getCanonicalPath() }, destFile, true, ZipUtil.NO_COMPRESSION); logger.error("Zip should fail when any input filename does not exist"); Assert.fail("Zip should fail when any input filename does not exist"); } catch (FileNotFoundException e) { logger.debug("Detecting non-existing input filename (String, File): OK"); } // Correct input filenames array, null destination file try { ZipUtil.zip(new String[] { srcFile.getCanonicalPath(), nestedSrcFile.getCanonicalPath() }, (File) null, true, ZipUtil.NO_COMPRESSION); logger.error("Zip should fail when destination File is null"); Assert.fail("Zip should fail when destination File is null"); } catch (IllegalArgumentException e) { logger.debug("Detecting null destination File (String, File): OK"); } // Correct input filenames, existing destination file try { ZipUtil.zip(new String[] { srcFile.getCanonicalPath(), nestedSrcFile.getCanonicalPath() }, sampleZip, true, ZipUtil.NO_COMPRESSION); logger.error("Zip should fail when destination file already exists"); Assert.fail("Zip should fail when destination file already exists"); } catch (IllegalArgumentException e) { logger.debug("Detecting existing destination File (String, File): OK"); } // Correct input filenames, invalid name for the zip file try { ZipUtil.zip(new String[] { srcFile.getCanonicalPath(), nestedSrcFile.getCanonicalPath() }, dummieFile, true, ZipUtil.NO_COMPRESSION); logger.error("Zip should fail when the destination File does not represent a zip file"); Assert.fail("Zip should fail when the destination File does not represent a zip file"); } catch (IllegalArgumentException e) { logger.debug("Detecting destination File not representing a valid zip file (String, File): OK"); } } catch (Exception e) { logger.error("Another exception was expected, but got {} instead: {}", e.getClass().getName(), e.getMessage()); Assert.fail("Another exception was expected, but got " + e.getClass().getName() + " instead: " + e.getMessage()); } }
From source file:org.opencastproject.util.ZipUtilTest.java
/** Check the behavior with bad arguments for the unzip signature String, String */ @Test/*ww w.j ava2s . com*/ public void badInputUnzipStrStr() throws Exception { File destFile = new File(destDir, "badInputStrStr"); try { // Null input filename, correct destination filename try { ZipUtil.unzip((String) null, destFile.getCanonicalPath()); logger.error("Unzip should fail when input filename is null"); Assert.fail("Unzip should fail when input filename is null"); } catch (IllegalArgumentException e) { logger.debug("Detecting null input filename (String, String): OK"); } // Empty input filename, correct destination filename try { ZipUtil.unzip("", destFile.getCanonicalPath()); logger.error("Unzip should fail when input filename is empty"); Assert.fail("Unzip should fail when input filename is empty"); } catch (IllegalArgumentException e) { logger.debug("Detecting empty input filename (String, String): OK"); } // Correct input filename, null destination filename try { ZipUtil.unzip(sampleZip.getCanonicalPath(), (String) null); logger.error("Unzip should fail when destination filename is null"); Assert.fail("Unzip should fail when destination filename is null"); } catch (IllegalArgumentException e) { logger.debug("Detecting null destination filename (String, String): OK"); } // Correct input filename, empty destination filename try { ZipUtil.unzip(sampleZip.getCanonicalPath(), ""); logger.error("Unzip should fail when destination filename is empty"); Assert.fail("Unzip should fail when destination filename is empty"); } catch (IllegalArgumentException e) { logger.debug("Detecting empty destination filename (String, String): OK"); } // Non-existing input filename, correct destination filename try { ZipUtil.unzip(dummieFile.getCanonicalPath(), destFile.getCanonicalPath()); logger.error("Unzip should fail when the input filename doesn't exists"); Assert.fail("Unzip should fail when the input filename doesn't exists"); } catch (FileNotFoundException e) { logger.debug("Detecting existing input filename (String, String): OK"); } // Invalid input filename (using a regular file as input), correct destination filename try { ZipUtil.unzip(srcFile.getCanonicalPath(), destFile.getCanonicalPath()); logger.error("Unzip should fail when the input filename does not represent a zip file"); Assert.fail("Unzip should fail when the input filename does not represent a zip file"); } catch (IllegalArgumentException e) { logger.debug("Detecting input filename not representing a valid zip file (String, String): OK"); } // Correct input filename, invalid destination filename (some existing regular file rather than a dir) try { ZipUtil.unzip(sampleZip.getCanonicalPath(), srcFile.getCanonicalPath()); logger.error("Unzip should fail when the destination filename does not represent a directory"); Assert.fail("Unzip should fail when the destination filename does not represent a directory"); } catch (IllegalArgumentException e) { logger.debug("Detecting destination filename not representing a directory (String, String): OK"); } } catch (Exception e) { logger.error("Another exception was expected, but got {} instead: {}", e.getClass().getName(), e.getMessage()); Assert.fail("Another exception was expected, but got " + e.getClass().getName() + "instead: " + e.getMessage()); } }