com.fujitsu.dc.test.jersey.box.dav.file.MoveFileHeaderValidateTest.java Source code

Java tutorial

Introduction

Here is the source code for com.fujitsu.dc.test.jersey.box.dav.file.MoveFileHeaderValidateTest.java

Source

/**
 * personium.io
 * Copyright 2014 FUJITSU LIMITED
 *
 * Licensed 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 com.fujitsu.dc.test.jersey.box.dav.file;

    import static org.fest.assertions.Assertions.assertThat;
    import static org.junit.Assert.assertEquals;

    import java.util.regex.Matcher;
    import java.util.regex.Pattern;

    import javax.ws.rs.core.MediaType;

    import org.apache.http.HttpHeaders;
    import org.apache.http.HttpStatus;
    import org.junit.Test;
    import org.junit.experimental.categories.Category;
    import org.junit.runner.RunWith;

    import com.fujitsu.dc.core.DcCoreException;
    import com.fujitsu.dc.test.categories.Integration;
    import com.fujitsu.dc.test.categories.Regression;
    import com.fujitsu.dc.test.categories.Unit;
    import com.fujitsu.dc.test.jersey.AbstractCase;
    import com.fujitsu.dc.test.jersey.DcRequest;
    import com.fujitsu.dc.test.jersey.DcResponse;
    import com.fujitsu.dc.test.jersey.DcRunner;
    import com.fujitsu.dc.test.jersey.ODataCommon;
    import com.fujitsu.dc.test.unit.core.UrlUtils;
    import com.fujitsu.dc.test.utils.DavResourceUtils;
    import com.fujitsu.dc.test.utils.TResponse;
    import com.sun.jersey.test.framework.JerseyTest;

    /**
     * WebDAV??MOVE????. <br />
     * ??????????????????
     * <ul>
     * <li></li>
     * <li></li>
     * <li></li>
     * </ul>
     * @see com.fujitsu.dc.test.jersey.box.dav.file.MoveFileTest
     */
    @RunWith(DcRunner.class)
    @Category({ Unit.class, Integration.class, Regression.class })
    public class MoveFileHeaderValidateTest extends JerseyTest {
        private static final String TOKEN = AbstractCase.MASTER_TOKEN_NAME;
        private static final String CELL_NAME = "testcell1";
        private static final String BOX_NAME = "box1";
        private static final String FILE_NAME = "file1.txt";
        private static final String FILE_BODY = "testFileBody";

        /**
         * .
         */
        public MoveFileHeaderValidateTest() {
            super("com.fujitsu.dc.core.rs");
        }

        /**
         * File?MOVE?Destination?????400????.
         */
        @Test
        public final void File?MOVE?Destination?????400 ????()
        {
            try {
                // ?
                DavResourceUtils.createWebDavFile(TOKEN, CELL_NAME, BOX_NAME + "/" + FILE_NAME, FILE_BODY,
                        MediaType.TEXT_PLAIN, HttpStatus.SC_CREATED);

                // File?
                String url = UrlUtils.box(CELL_NAME, BOX_NAME, FILE_NAME);
                DcRequest req = DcRequest.move(url);
                req.header(HttpHeaders.AUTHORIZATION, AbstractCase.BEARER_MASTER_TOKEN);

                // 
                DcResponse response = AbstractCase.request(req);
                assertThat(response.getStatusCode()).isEqualTo(HttpStatus.SC_BAD_REQUEST);
                DcCoreException expectedException = DcCoreException.Dav.REQUIRED_REQUEST_HEADER_NOT_EXIST
                        .params(HttpHeaders.DESTINATION);
                ODataCommon.checkErrorResponseBody(response, expectedException.getCode(),
                        expectedException.getMessage());

            } finally {
                DavResourceUtils.deleteWebDavFile(CELL_NAME, TOKEN, BOX_NAME, FILE_NAME);
            }
        }

        /**
         * File?MOVE?Destination?????400????.
         */
        @Test
        public final void File?MOVE?Destination?????400 ????()
        {
            final String destination = "";
            try {
                // ?
                DavResourceUtils.createWebDavFile(TOKEN, CELL_NAME, BOX_NAME + "/" + FILE_NAME, FILE_BODY,
                        MediaType.TEXT_PLAIN, HttpStatus.SC_CREATED);

                // File?
                String url = UrlUtils.box(CELL_NAME, BOX_NAME, FILE_NAME);
                DcRequest req = DcRequest.move(url);
                req.header(HttpHeaders.AUTHORIZATION, AbstractCase.BEARER_MASTER_TOKEN);
                req.header(HttpHeaders.DESTINATION, destination);

                // 
                DcResponse response = AbstractCase.request(req);
                assertThat(response.getStatusCode()).isEqualTo(HttpStatus.SC_BAD_REQUEST);
                DcCoreException expectedException = DcCoreException.Dav.REQUIRED_REQUEST_HEADER_NOT_EXIST
                        .params(HttpHeaders.DESTINATION, destination);
                ODataCommon.checkErrorResponseBody(response, expectedException.getCode(),
                        expectedException.getMessage());

                // ?????
                DavResourceUtils.getWebDav(CELL_NAME, TOKEN, BOX_NAME, FILE_NAME, HttpStatus.SC_OK);

            } finally {
                DavResourceUtils.deleteWebDavFile(CELL_NAME, TOKEN, BOX_NAME, FILE_NAME);
            }
        }

        /**
         * File?MOVE?Destination?URI????????400????.
         */
        @Test
        public final void File?MOVE?Destination?URI????????400 ????()
        {
            final String destination = "http/?#/dest#?#://destFile.txt";
            try {
                // ?
                DavResourceUtils.createWebDavFile(TOKEN, CELL_NAME, BOX_NAME + "/" + FILE_NAME, FILE_BODY,
                        MediaType.TEXT_PLAIN, HttpStatus.SC_CREATED);

                // File?
                String url = UrlUtils.box(CELL_NAME, BOX_NAME, FILE_NAME);
                DcRequest req = DcRequest.move(url);
                req.header(HttpHeaders.AUTHORIZATION, AbstractCase.BEARER_MASTER_TOKEN);
                req.header(HttpHeaders.DESTINATION, destination);

                // 
                DcResponse response = AbstractCase.request(req);
                assertThat(response.getStatusCode()).isEqualTo(HttpStatus.SC_BAD_REQUEST);
                DcCoreException expectedException = DcCoreException.Dav.INVALID_REQUEST_HEADER
                        .params(HttpHeaders.DESTINATION, destination);
                ODataCommon.checkErrorResponseBody(response, expectedException.getCode(),
                        expectedException.getMessage());

                // ?????
                DavResourceUtils.getWebDav(CELL_NAME, TOKEN, BOX_NAME, FILE_NAME, HttpStatus.SC_OK);
            } finally {
                DavResourceUtils.deleteWebDavFile(CELL_NAME, TOKEN, BOX_NAME, FILE_NAME);
            }
        }

        /**
         * File?MOVE?Destination??FTP??URI????400????.
         */
        @Test
        public final void File?MOVE?Destination? ?FTP??URI????400 ????()
        {
        final String destFileName = "destFile.txt";
        final String destination = UrlUtils.box(CELL_NAME, BOX_NAME, destFileName).replaceAll("http[s]{0,1}", "ftp");
        try {
            // ?
            DavResourceUtils.createWebDavFile(TOKEN, CELL_NAME,
                    BOX_NAME + "/" + FILE_NAME, FILE_BODY, MediaType.TEXT_PLAIN, HttpStatus.SC_CREATED);

            // File?
            String url = UrlUtils.box(CELL_NAME, BOX_NAME, FILE_NAME);
            DcRequest req = DcRequest.move(url);
            req.header(HttpHeaders.AUTHORIZATION, AbstractCase.BEARER_MASTER_TOKEN);
            req.header(HttpHeaders.DESTINATION, destination);

            // 
            DcResponse response = AbstractCase.request(req);
            assertThat(response.getStatusCode()).isEqualTo(HttpStatus.SC_BAD_REQUEST);
            DcCoreException expectedException = DcCoreException.Dav.INVALID_REQUEST_HEADER.params(
                    HttpHeaders.DESTINATION, destination);
            ODataCommon.checkErrorResponseBody(response, expectedException.getCode(), expectedException.getMessage());

            // ?????
            DavResourceUtils.getWebDav(CELL_NAME, TOKEN , BOX_NAME, FILE_NAME, HttpStatus.SC_OK);
        } finally {
            DavResourceUtils.deleteWebDavFile(CELL_NAME, TOKEN, BOX_NAME, FILE_NAME);
        }
    }

    /**
     * File?MOVE?Overwrite?????????????????.
     */
    @Test
    public final void File?MOVE?Overwrite?????????????????()
        {
            final String destFileName = "destFile.txt";
            final String destination = UrlUtils.box(CELL_NAME, BOX_NAME, destFileName);
            try {
                // ?
                DavResourceUtils.createWebDavFile(TOKEN, CELL_NAME, BOX_NAME + "/" + FILE_NAME, FILE_BODY,
                        MediaType.TEXT_PLAIN, HttpStatus.SC_CREATED);

                // File?
                String url = UrlUtils.box(CELL_NAME, BOX_NAME, FILE_NAME);
                DcRequest req = DcRequest.move(url);
                req.header(HttpHeaders.AUTHORIZATION, AbstractCase.BEARER_MASTER_TOKEN);
                req.header(HttpHeaders.DESTINATION, destination);

                // 
                DcResponse response = AbstractCase.request(req);
                assertThat(response.getStatusCode()).isEqualTo(HttpStatus.SC_CREATED);

                // ???????
                DavResourceUtils.getWebDav(CELL_NAME, TOKEN, BOX_NAME, FILE_NAME, HttpStatus.SC_NOT_FOUND);
                // ?????
                DavResourceUtils.getWebDav(CELL_NAME, TOKEN, BOX_NAME, destFileName, HttpStatus.SC_OK);
            } finally {
                DavResourceUtils.deleteWebDavFile(CELL_NAME, TOKEN, BOX_NAME, FILE_NAME);
                DavResourceUtils.deleteWebDavFile(CELL_NAME, TOKEN, BOX_NAME, destFileName);
            }
        }

    /**
     * File?MOVE?Overwrite????400????.
     */
    @Test
    public final void  File?MOVE?Overwrite????400 ????()
        {
            final String destFileName = "destFile.txt";
            final String destination = UrlUtils.box(CELL_NAME, BOX_NAME, destFileName);
            try {
                // ?
                DavResourceUtils.createWebDavFile(TOKEN, CELL_NAME, BOX_NAME + "/" + FILE_NAME, FILE_BODY,
                        MediaType.TEXT_PLAIN, HttpStatus.SC_CREATED);

                // File?
                String url = UrlUtils.box(CELL_NAME, BOX_NAME, FILE_NAME);
                DcRequest req = DcRequest.move(url);
                req.header(HttpHeaders.AUTHORIZATION, AbstractCase.BEARER_MASTER_TOKEN);
                req.header(HttpHeaders.DESTINATION, destination);
                req.header(HttpHeaders.OVERWRITE, "");

                // 
                DcResponse response = AbstractCase.request(req);
                assertThat(response.getStatusCode()).isEqualTo(HttpStatus.SC_BAD_REQUEST);
                DcCoreException expectedException = DcCoreException.Dav.INVALID_REQUEST_HEADER
                        .params(HttpHeaders.OVERWRITE, "");
                ODataCommon.checkErrorResponseBody(response, expectedException.getCode(),
                        expectedException.getMessage());

                // ?????
                DavResourceUtils.getWebDav(CELL_NAME, TOKEN, BOX_NAME, FILE_NAME, HttpStatus.SC_OK);
                // ???????
                DavResourceUtils.getWebDav(CELL_NAME, TOKEN, BOX_NAME, destFileName, HttpStatus.SC_NOT_FOUND);
            } finally {
                DavResourceUtils.deleteWebDavFile(CELL_NAME, TOKEN, BOX_NAME, FILE_NAME);
                DavResourceUtils.deleteWebDavFile(CELL_NAME, TOKEN, BOX_NAME, destFileName);
            }
        }

    /**
     * File?MOVE?Overwrite?T?????????????.
     */
    @Test
    public final void File?MOVE?Overwrite?T?????????????()
        {
            final String destFileName = "destFile.txt";
            final String destination = UrlUtils.box(CELL_NAME, BOX_NAME, destFileName);
            try {
                // ?
                DavResourceUtils.createWebDavFile(TOKEN, CELL_NAME, BOX_NAME + "/" + FILE_NAME, FILE_BODY,
                        MediaType.TEXT_PLAIN, HttpStatus.SC_CREATED);

                // File?
                String url = UrlUtils.box(CELL_NAME, BOX_NAME, FILE_NAME);
                DcRequest req = DcRequest.move(url);
                req.header(HttpHeaders.AUTHORIZATION, AbstractCase.BEARER_MASTER_TOKEN);
                req.header(HttpHeaders.DESTINATION, destination);
                req.header(HttpHeaders.OVERWRITE, "T");

                // 
                DcResponse response = AbstractCase.request(req);
                assertThat(response.getStatusCode()).isEqualTo(HttpStatus.SC_CREATED);

                // ???????
                DavResourceUtils.getWebDav(CELL_NAME, TOKEN, BOX_NAME, FILE_NAME, HttpStatus.SC_NOT_FOUND);
                // ?????
                DavResourceUtils.getWebDav(CELL_NAME, TOKEN, BOX_NAME, destFileName, HttpStatus.SC_OK);
            } finally {
                DavResourceUtils.deleteWebDavFile(CELL_NAME, TOKEN, BOX_NAME, FILE_NAME);
                DavResourceUtils.deleteWebDavFile(CELL_NAME, TOKEN, BOX_NAME, destFileName);
            }
        }

    /**
     * File?MOVE?Overwrite?F?????????????.
     */
    @Test
    public final void File?MOVE?Overwrite?F?????????????()
        {
            final String destFileName = "destFile.txt";
            final String destination = UrlUtils.box(CELL_NAME, BOX_NAME, destFileName);
            try {
                // ?
                DavResourceUtils.createWebDavFile(TOKEN, CELL_NAME, BOX_NAME + "/" + FILE_NAME, FILE_BODY,
                        MediaType.TEXT_PLAIN, HttpStatus.SC_CREATED);

                // File?
                String url = UrlUtils.box(CELL_NAME, BOX_NAME, FILE_NAME);
                DcRequest req = DcRequest.move(url);
                req.header(HttpHeaders.AUTHORIZATION, AbstractCase.BEARER_MASTER_TOKEN);
                req.header(HttpHeaders.DESTINATION, destination);
                req.header(HttpHeaders.OVERWRITE, "F");

                // 
                DcResponse response = AbstractCase.request(req);
                assertThat(response.getStatusCode()).isEqualTo(HttpStatus.SC_CREATED);

                // ???????
                DavResourceUtils.getWebDav(CELL_NAME, TOKEN, BOX_NAME, FILE_NAME, HttpStatus.SC_NOT_FOUND);
                // ?????
                DavResourceUtils.getWebDav(CELL_NAME, TOKEN, BOX_NAME, destFileName, HttpStatus.SC_OK);
            } finally {
                DavResourceUtils.deleteWebDavFile(CELL_NAME, TOKEN, BOX_NAME, FILE_NAME);
                DavResourceUtils.deleteWebDavFile(CELL_NAME, TOKEN, BOX_NAME, destFileName);
            }
        }

    /**
     * File?MOVE?Overwrite?????????????400????.
     */
    @Test
    public final void File?MOVE?Overwrite?????????????400 ????()
        {
            final String destFileName = "destFile.txt";
            final String destination = UrlUtils.box(CELL_NAME, BOX_NAME, destFileName);
            try {
                // ?
                DavResourceUtils.createWebDavFile(TOKEN, CELL_NAME, BOX_NAME + "/" + FILE_NAME, FILE_BODY,
                        MediaType.TEXT_PLAIN, HttpStatus.SC_CREATED);

                // File?
                String url = UrlUtils.box(CELL_NAME, BOX_NAME, FILE_NAME);
                DcRequest req = DcRequest.move(url);
                req.header(HttpHeaders.AUTHORIZATION, AbstractCase.BEARER_MASTER_TOKEN);
                req.header(HttpHeaders.DESTINATION, destination);
                req.header(HttpHeaders.OVERWRITE, "Y");

                // 
                DcResponse response = AbstractCase.request(req);
                assertThat(response.getStatusCode()).isEqualTo(HttpStatus.SC_BAD_REQUEST);
                DcCoreException expectedException = DcCoreException.Dav.INVALID_REQUEST_HEADER
                        .params(HttpHeaders.OVERWRITE, "Y");
                ODataCommon.checkErrorResponseBody(response, expectedException.getCode(),
                        expectedException.getMessage());

                // ?????
                DavResourceUtils.getWebDav(CELL_NAME, TOKEN, BOX_NAME, FILE_NAME, HttpStatus.SC_OK);
                // ???????
                DavResourceUtils.getWebDav(CELL_NAME, TOKEN, BOX_NAME, destFileName, HttpStatus.SC_NOT_FOUND);
            } finally {
                DavResourceUtils.deleteWebDavFile(CELL_NAME, TOKEN, BOX_NAME, FILE_NAME);
                DavResourceUtils.deleteWebDavFile(CELL_NAME, TOKEN, BOX_NAME, destFileName);
            }
        }

    /**
     * File?MOVE?Depth???????????.
     */
    @Test
    public final void File?MOVE?Depth???????????()
        {
            final String destFileName = "destFile.txt";
            final String destination = UrlUtils.box(CELL_NAME, BOX_NAME, destFileName);
            try {
                // ?
                DavResourceUtils.createWebDavFile(TOKEN, CELL_NAME, BOX_NAME + "/" + FILE_NAME, FILE_BODY,
                        MediaType.TEXT_PLAIN, HttpStatus.SC_CREATED);

                // File?
                String url = UrlUtils.box(CELL_NAME, BOX_NAME, FILE_NAME);
                DcRequest req = DcRequest.move(url);
                req.header(HttpHeaders.AUTHORIZATION, AbstractCase.BEARER_MASTER_TOKEN);
                req.header(HttpHeaders.DESTINATION, destination);
                req.header(HttpHeaders.OVERWRITE, "T");

                // 
                DcResponse response = AbstractCase.request(req);
                assertThat(response.getStatusCode()).isEqualTo(HttpStatus.SC_CREATED);

                // ???????
                DavResourceUtils.getWebDav(CELL_NAME, TOKEN, BOX_NAME, FILE_NAME, HttpStatus.SC_NOT_FOUND);
                // ?????
                DavResourceUtils.getWebDav(CELL_NAME, TOKEN, BOX_NAME, destFileName, HttpStatus.SC_OK);
            } finally {
                DavResourceUtils.deleteWebDavFile(CELL_NAME, TOKEN, BOX_NAME, FILE_NAME);
                DavResourceUtils.deleteWebDavFile(CELL_NAME, TOKEN, BOX_NAME, destFileName);
            }
        }

    /**
     * File?MOVE?Depth?????400????.
     */
    @Test
    public final void File?MOVE?Depth?????400 ????()
        {
            final String depth = "";
            final String destFileName = "destFile.txt";
            final String destination = UrlUtils.box(CELL_NAME, BOX_NAME, destFileName);
            try {
                // ?
                DavResourceUtils.createWebDavFile(TOKEN, CELL_NAME, BOX_NAME + "/" + FILE_NAME, FILE_BODY,
                        MediaType.TEXT_PLAIN, HttpStatus.SC_CREATED);

                // File?
                String url = UrlUtils.box(CELL_NAME, BOX_NAME, FILE_NAME);
                DcRequest req = DcRequest.move(url);
                req.header(HttpHeaders.AUTHORIZATION, AbstractCase.BEARER_MASTER_TOKEN);
                req.header(HttpHeaders.DESTINATION, destination);
                req.header(HttpHeaders.DEPTH, depth);

                // 
                DcResponse response = AbstractCase.request(req);
                assertEquals(HttpStatus.SC_BAD_REQUEST, response.getStatusCode());
                DcCoreException expectedException = DcCoreException.Dav.INVALID_DEPTH_HEADER.params(depth);
                ODataCommon.checkErrorResponseBody(response, expectedException.getCode(),
                        expectedException.getMessage());

                // ?????
                DavResourceUtils.getWebDav(CELL_NAME, TOKEN, BOX_NAME, FILE_NAME, HttpStatus.SC_OK);
                // ???????
                DavResourceUtils.getWebDav(CELL_NAME, TOKEN, BOX_NAME, destFileName, HttpStatus.SC_NOT_FOUND);
            } finally {
                DavResourceUtils.deleteWebDavFile(CELL_NAME, TOKEN, BOX_NAME, FILE_NAME);
                DavResourceUtils.deleteWebDavFile(CELL_NAME, TOKEN, BOX_NAME, destFileName);
            }
        }

    /**
     * File?MOVE?Depth?infinity??????????.
     */
    @Test
    public final void File?MOVE?Depth?infinity??????????()
        {
            final String depth = "infinity";
            final String destFileName = "destFile.txt";
            final String destination = UrlUtils.box(CELL_NAME, BOX_NAME, destFileName);
            try {
                // ?
                DavResourceUtils.createWebDavFile(TOKEN, CELL_NAME, BOX_NAME + "/" + FILE_NAME, FILE_BODY,
                        MediaType.TEXT_PLAIN, HttpStatus.SC_CREATED);

                // File?
                String url = UrlUtils.box(CELL_NAME, BOX_NAME, FILE_NAME);
                DcRequest req = DcRequest.move(url);
                req.header(HttpHeaders.AUTHORIZATION, AbstractCase.BEARER_MASTER_TOKEN);
                req.header(HttpHeaders.DESTINATION, destination);
                req.header(HttpHeaders.DEPTH, depth);

                // 
                DcResponse response = AbstractCase.request(req);
                assertEquals(HttpStatus.SC_CREATED, response.getStatusCode());

                // ???????
                DavResourceUtils.getWebDav(CELL_NAME, TOKEN, BOX_NAME, FILE_NAME, HttpStatus.SC_NOT_FOUND);
                // ?????
                DavResourceUtils.getWebDav(CELL_NAME, TOKEN, BOX_NAME, destFileName, HttpStatus.SC_OK);
            } finally {
                DavResourceUtils.deleteWebDavFile(CELL_NAME, TOKEN, BOX_NAME, FILE_NAME);
                DavResourceUtils.deleteWebDavFile(CELL_NAME, TOKEN, BOX_NAME, destFileName);
            }
        }

        /**
         * File?MOVE?Depth?INFInITY??????????.
         */
        @Test
        public final void File?MOVE?Depth?INFInITY??????????()
        {
            final String depth = "INFInITY";
            final String destFileName = "destFile.txt";
            final String destination = UrlUtils.box(CELL_NAME, BOX_NAME, destFileName);
            try {
                // ?
                DavResourceUtils.createWebDavFile(TOKEN, CELL_NAME, BOX_NAME + "/" + FILE_NAME, FILE_BODY,
                        MediaType.TEXT_PLAIN, HttpStatus.SC_CREATED);

                // File?
                String url = UrlUtils.box(CELL_NAME, BOX_NAME, FILE_NAME);
                DcRequest req = DcRequest.move(url);
                req.header(HttpHeaders.AUTHORIZATION, AbstractCase.BEARER_MASTER_TOKEN);
                req.header(HttpHeaders.DESTINATION, destination);
                req.header(HttpHeaders.DEPTH, depth);

                // 
                DcResponse response = AbstractCase.request(req);
                assertEquals(HttpStatus.SC_CREATED, response.getStatusCode());

                // ???????
                DavResourceUtils.getWebDav(CELL_NAME, TOKEN, BOX_NAME, FILE_NAME, HttpStatus.SC_NOT_FOUND);
                // ?????
                DavResourceUtils.getWebDav(CELL_NAME, TOKEN, BOX_NAME, destFileName, HttpStatus.SC_OK);
            } finally {
                DavResourceUtils.deleteWebDavFile(CELL_NAME, TOKEN, BOX_NAME, FILE_NAME);
                DavResourceUtils.deleteWebDavFile(CELL_NAME, TOKEN, BOX_NAME, destFileName);
            }
        }

        /**
         * File?MOVE?Depth?infinity?????400????.
         */
        @Test
        public final void File?MOVE?Depth?infinity?????400 ????()
        {
            final String depth = "1";
            final String destFileName = "destFile.txt";
            final String destination = UrlUtils.box(CELL_NAME, BOX_NAME, destFileName);
            try {
                // ?
                DavResourceUtils.createWebDavFile(TOKEN, CELL_NAME, BOX_NAME + "/" + FILE_NAME, FILE_BODY,
                        MediaType.TEXT_PLAIN, HttpStatus.SC_CREATED);

                // File?
                String url = UrlUtils.box(CELL_NAME, BOX_NAME, FILE_NAME);
                DcRequest req = DcRequest.move(url);
                req.header(HttpHeaders.AUTHORIZATION, AbstractCase.BEARER_MASTER_TOKEN);
                req.header(HttpHeaders.DESTINATION, destination);
                req.header(HttpHeaders.DEPTH, depth);

                // 
                DcResponse response = AbstractCase.request(req);
                assertEquals(HttpStatus.SC_BAD_REQUEST, response.getStatusCode());
                DcCoreException expectedException = DcCoreException.Dav.INVALID_DEPTH_HEADER.params(depth);
                ODataCommon.checkErrorResponseBody(response, expectedException.getCode(),
                        expectedException.getMessage());

                // ?????
                DavResourceUtils.getWebDav(CELL_NAME, TOKEN, BOX_NAME, FILE_NAME, HttpStatus.SC_OK);
                // ???????
                DavResourceUtils.getWebDav(CELL_NAME, TOKEN, BOX_NAME, destFileName, HttpStatus.SC_NOT_FOUND);
            } finally {
                DavResourceUtils.deleteWebDavFile(CELL_NAME, TOKEN, BOX_NAME, FILE_NAME);
                DavResourceUtils.deleteWebDavFile(CELL_NAME, TOKEN, BOX_NAME, destFileName);
            }
        }

        /**
         * File?MOVE?If_Match??????????.
         */
        @Test
        public final void File?MOVE?If_Match??????????()
        {
            final String depth = "infinity";
            final String destFileName = "destFile.txt";
            final String destination = UrlUtils.box(CELL_NAME, BOX_NAME, destFileName);
            try {
                // ?
                DavResourceUtils.createWebDavFile(TOKEN, CELL_NAME, BOX_NAME + "/" + FILE_NAME, FILE_BODY,
                        MediaType.TEXT_PLAIN, HttpStatus.SC_CREATED);

                // File?
                String url = UrlUtils.box(CELL_NAME, BOX_NAME, FILE_NAME);
                DcRequest req = DcRequest.move(url);
                req.header(HttpHeaders.AUTHORIZATION, AbstractCase.BEARER_MASTER_TOKEN);
                req.header(HttpHeaders.DESTINATION, destination);
                req.header(HttpHeaders.DEPTH, depth);
                req.header(HttpHeaders.OVERWRITE, "T");

                // 
                DcResponse response = AbstractCase.request(req);
                assertEquals(HttpStatus.SC_CREATED, response.getStatusCode());

                // ???????
                DavResourceUtils.getWebDav(CELL_NAME, TOKEN, BOX_NAME, FILE_NAME, HttpStatus.SC_NOT_FOUND);
                // ?????
                DavResourceUtils.getWebDav(CELL_NAME, TOKEN, BOX_NAME, destFileName, HttpStatus.SC_OK);
            } finally {
                DavResourceUtils.deleteWebDavFile(CELL_NAME, TOKEN, BOX_NAME, FILE_NAME);
                DavResourceUtils.deleteWebDavFile(CELL_NAME, TOKEN, BOX_NAME, destFileName);
            }
        }

        /**
         * File?MOVE?If_Match?????400????.
         */
        @Test
        public final void File?MOVE?If_Match?????400 ????()
        {
            final String depth = "infinity";
            final String destFileName = "destFile.txt";
            final String destination = UrlUtils.box(CELL_NAME, BOX_NAME, destFileName);
            try {
                // ?
                DavResourceUtils.createWebDavFile(TOKEN, CELL_NAME, BOX_NAME + "/" + FILE_NAME, FILE_BODY,
                        MediaType.TEXT_PLAIN, HttpStatus.SC_CREATED);

                // File?
                String url = UrlUtils.box(CELL_NAME, BOX_NAME, FILE_NAME);
                DcRequest req = DcRequest.move(url);
                req.header(HttpHeaders.AUTHORIZATION, AbstractCase.BEARER_MASTER_TOKEN);
                req.header(HttpHeaders.DESTINATION, destination);
                req.header(HttpHeaders.DEPTH, depth);
                req.header(HttpHeaders.OVERWRITE, "T");
                req.header(HttpHeaders.IF_MATCH, "");

                // 
                DcResponse response = AbstractCase.request(req);
                assertEquals(HttpStatus.SC_PRECONDITION_FAILED, response.getStatusCode());
                DcCoreException expectedException = DcCoreException.Dav.ETAG_NOT_MATCH;
                ODataCommon.checkErrorResponseBody(response, expectedException.getCode(),
                        expectedException.getMessage());

                // ?????
                DavResourceUtils.getWebDav(CELL_NAME, TOKEN, BOX_NAME, FILE_NAME, HttpStatus.SC_OK);
                // ???????
                DavResourceUtils.getWebDav(CELL_NAME, TOKEN, BOX_NAME, destFileName, HttpStatus.SC_NOT_FOUND);
            } finally {
                DavResourceUtils.deleteWebDavFile(CELL_NAME, TOKEN, BOX_NAME, FILE_NAME);
                DavResourceUtils.deleteWebDavFile(CELL_NAME, TOKEN, BOX_NAME, destFileName);
            }
        }

        /**
         * File?MOVE?If_Match??????????.
         */
        @Test
        public final void File?MOVE?If_Match??????????()
        {
            final String depth = "infinity";
            final String destFileName = "destFile.txt";
            final String destination = UrlUtils.box(CELL_NAME, BOX_NAME, destFileName);
            try {
                // ?
                DavResourceUtils.createWebDavFile(TOKEN, CELL_NAME, BOX_NAME + "/" + FILE_NAME, FILE_BODY,
                        MediaType.TEXT_PLAIN, HttpStatus.SC_CREATED);

                // File?
                String url = UrlUtils.box(CELL_NAME, BOX_NAME, FILE_NAME);
                DcRequest req = DcRequest.move(url);
                req.header(HttpHeaders.AUTHORIZATION, AbstractCase.BEARER_MASTER_TOKEN);
                req.header(HttpHeaders.DESTINATION, destination);
                req.header(HttpHeaders.DEPTH, depth);
                req.header(HttpHeaders.OVERWRITE, "T");
                req.header(HttpHeaders.IF_MATCH, "*");

                // 
                DcResponse response = AbstractCase.request(req);
                assertEquals(HttpStatus.SC_CREATED, response.getStatusCode());

                // ???????
                DavResourceUtils.getWebDav(CELL_NAME, TOKEN, BOX_NAME, FILE_NAME, HttpStatus.SC_NOT_FOUND);
                // ?????
                DavResourceUtils.getWebDav(CELL_NAME, TOKEN, BOX_NAME, destFileName, HttpStatus.SC_OK);
            } finally {
                DavResourceUtils.deleteWebDavFile(CELL_NAME, TOKEN, BOX_NAME, FILE_NAME);
                DavResourceUtils.deleteWebDavFile(CELL_NAME, TOKEN, BOX_NAME, destFileName);
            }
        }

        /**
         * File?MOVE?If_Match?????????412????.
         */
        @Test
        public final void File?MOVE?If_Match???? ?????412 ????()
        {
            final String depth = "infinity";
            final String destFileName = "destFile.txt";
            final String destination = UrlUtils.box(CELL_NAME, BOX_NAME, destFileName);
            try {
                // ?
                DavResourceUtils.createWebDavFile(TOKEN, CELL_NAME, BOX_NAME + "/" + FILE_NAME, FILE_BODY,
                        MediaType.TEXT_PLAIN, HttpStatus.SC_CREATED);

                TResponse res = DavResourceUtils.getWebDav(CELL_NAME, TOKEN, BOX_NAME, FILE_NAME, HttpStatus.SC_OK);
                String etag = res.getHeader(HttpHeaders.ETAG);

                // File?
                String url = UrlUtils.box(CELL_NAME, BOX_NAME, FILE_NAME);
                DcRequest req = DcRequest.move(url);
                req.header(HttpHeaders.AUTHORIZATION, AbstractCase.BEARER_MASTER_TOKEN);
                req.header(HttpHeaders.DESTINATION, destination);
                req.header(HttpHeaders.DEPTH, depth);
                req.header(HttpHeaders.OVERWRITE, "T");
                req.header(HttpHeaders.IF_MATCH, etag + "dummy");

                // 
                DcResponse response = AbstractCase.request(req);
                assertEquals(HttpStatus.SC_PRECONDITION_FAILED, response.getStatusCode());
                DcCoreException expectedException = DcCoreException.Dav.ETAG_NOT_MATCH;
                ODataCommon.checkErrorResponseBody(response, expectedException.getCode(),
                        expectedException.getMessage());

                // ?????
                DavResourceUtils.getWebDav(CELL_NAME, TOKEN, BOX_NAME, FILE_NAME, HttpStatus.SC_OK);
                // ???????
                DavResourceUtils.getWebDav(CELL_NAME, TOKEN, BOX_NAME, destFileName, HttpStatus.SC_NOT_FOUND);
            } finally {
                DavResourceUtils.deleteWebDavFile(CELL_NAME, TOKEN, BOX_NAME, FILE_NAME);
                DavResourceUtils.deleteWebDavFile(CELL_NAME, TOKEN, BOX_NAME, destFileName);
            }
        }

        /**
         * File?MOVE?If_Match??????????.
         */
        @Test
        public final void File?MOVE?If_Match?? ????????()
        {
            final String depth = "infinity";
            final String destFileName = "destFile.txt";
            final String destination = UrlUtils.box(CELL_NAME, BOX_NAME, destFileName);
            try {
                // ?
                DavResourceUtils.createWebDavFile(TOKEN, CELL_NAME, BOX_NAME + "/" + FILE_NAME, FILE_BODY,
                        MediaType.TEXT_PLAIN, HttpStatus.SC_CREATED);

                TResponse res = DavResourceUtils.getWebDav(CELL_NAME, TOKEN, BOX_NAME, FILE_NAME, HttpStatus.SC_OK);
                String etag = res.getHeader(HttpHeaders.ETAG);

                // File?
                String url = UrlUtils.box(CELL_NAME, BOX_NAME, FILE_NAME);
                DcRequest req = DcRequest.move(url);
                req.header(HttpHeaders.AUTHORIZATION, AbstractCase.BEARER_MASTER_TOKEN);
                req.header(HttpHeaders.DESTINATION, destination);
                req.header(HttpHeaders.DEPTH, depth);
                req.header(HttpHeaders.OVERWRITE, "T");
                req.header(HttpHeaders.IF_MATCH, etag);

                // 
                DcResponse response = AbstractCase.request(req);
                assertEquals(HttpStatus.SC_CREATED, response.getStatusCode());

                // ???????
                DavResourceUtils.getWebDav(CELL_NAME, TOKEN, BOX_NAME, FILE_NAME, HttpStatus.SC_NOT_FOUND);
                // ?????
                DavResourceUtils.getWebDav(CELL_NAME, TOKEN, BOX_NAME, destFileName, HttpStatus.SC_OK);
            } finally {
                DavResourceUtils.deleteWebDavFile(CELL_NAME, TOKEN, BOX_NAME, FILE_NAME);
                DavResourceUtils.deleteWebDavFile(CELL_NAME, TOKEN, BOX_NAME, destFileName);
            }
        }

        /**
         * Etag???.
         * @param etag Etag
         * @return ?
         */
        public static long getEtagVersion(String etag) {
            // version?
            Pattern pattern = Pattern.compile("^\"([0-9]+)-([0-9]+)\"$");
            Matcher m = pattern.matcher(etag);
            return Long.parseLong(m.replaceAll("$1"));
        }

    }