Add callback for delete operation.
[cyberduck.git] / test / ch / cyberduck / core / openstack / SwiftExceptionMappingServiceTest.java
blobb676dcdf33f2c4d8a22c868881c9dafd969132f7
1 package ch.cyberduck.core.openstack;
3 /*
4 * Copyright (c) 2013 David Kocher. All rights reserved.
5 * http://cyberduck.ch/
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * Bug fixes, suggestions and comments should be sent to:
18 * dkocher@cyberduck.ch
21 import ch.cyberduck.core.AbstractTestCase;
22 import ch.cyberduck.core.Path;
23 import ch.cyberduck.core.exception.AccessDeniedException;
24 import ch.cyberduck.core.exception.ConnectionTimeoutException;
25 import ch.cyberduck.core.ftp.FTPExceptionMappingService;
27 import org.apache.http.Header;
28 import org.apache.http.ProtocolVersion;
29 import org.apache.http.StatusLine;
30 import org.apache.http.message.BasicStatusLine;
31 import org.junit.Test;
33 import java.net.SocketTimeoutException;
34 import java.util.EnumSet;
36 import ch.iterate.openstack.swift.exception.GenericException;
38 import static org.junit.Assert.assertEquals;
39 import static org.junit.Assert.assertTrue;
41 /**
42 * @version $Id$
44 public class SwiftExceptionMappingServiceTest extends AbstractTestCase {
46 @Test
47 public void testLoginFailure() throws Exception {
48 final GenericException f = new GenericException(
49 "message", new Header[]{}, new BasicStatusLine(new ProtocolVersion("http", 1, 1), 403, "Forbidden"));
50 assertTrue(new SwiftExceptionMappingService().map(f) instanceof AccessDeniedException);
51 assertEquals("Access denied", new SwiftExceptionMappingService().map(f).getMessage());
52 assertEquals("Message. 403 Forbidden. Please contact your web hosting service provider for assistance.", new SwiftExceptionMappingService().map(f).getDetail());
55 @Test
56 public void testMap() throws Exception {
57 assertEquals("Message. 500 reason.", new SwiftExceptionMappingService().map(
58 new GenericException("message", null, new StatusLine() {
59 @Override
60 public ProtocolVersion getProtocolVersion() {
61 throw new UnsupportedOperationException();
64 @Override
65 public int getStatusCode() {
66 return 500;
69 @Override
70 public String getReasonPhrase() {
71 return "reason";
73 })).getDetail());
76 @Test
77 public void testSocketTimeout() throws Exception {
78 assertEquals(ConnectionTimeoutException.class, new FTPExceptionMappingService()
79 .map(new SocketTimeoutException()).getClass());
80 assertEquals(ConnectionTimeoutException.class, new FTPExceptionMappingService()
81 .map("message", new SocketTimeoutException()).getClass());
82 assertEquals(ConnectionTimeoutException.class, new FTPExceptionMappingService()
83 .map("message", new SocketTimeoutException(), new Path("/f", EnumSet.of(Path.Type.file))).getClass());