7fc346e7d99ac1f5f1e9e43b4ddd3bb1c1e94773
[pub/Android/ownCloud.git] /
1 /* ownCloud webDAV Library for Android is available under MIT license
2 * Copyright (C) 2014 ownCloud (http://www.owncloud.org/)
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a copy
5 * of this software and associated documentation files (the "Software"), to deal
6 * in the Software without restriction, including without limitation the rights
7 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 * copies of the Software, and to permit persons to whom the Software is
9 * furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
13 *
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
18 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
19 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21 * THE SOFTWARE.
22 *
23 */
24 package com.owncloud.android.oc_framework_test_project.test;
25
26 import java.text.SimpleDateFormat;
27 import java.util.Date;
28
29 import com.owncloud.android.oc_framework.operations.RemoteOperationResult;
30 import com.owncloud.android.oc_framework.operations.RemoteOperationResult.ResultCode;
31 import com.owncloud.android.oc_framework_test_project.TestActivity;
32
33 import android.test.ActivityInstrumentationTestCase2;
34
35 /**
36 * Class to test Create Folder Operation
37 * @author masensio
38 *
39 */
40 public class CreateFolderTest extends ActivityInstrumentationTestCase2<TestActivity> {
41
42 private TestActivity mActivity;
43 private String mCurrentDate;
44
45 public CreateFolderTest() {
46 super(TestActivity.class);
47
48 SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd_HHmmss");
49 mCurrentDate = sdf.format(new Date());
50 }
51
52 @Override
53 protected void setUp() throws Exception {
54 super.setUp();
55 setActivityInitialTouchMode(false);
56 mActivity = getActivity();
57 }
58
59 /**
60 * Test Create Folder
61 */
62 public void testCreateFolder() {
63
64 String remotePath = "/testCreateFolder" + mCurrentDate;
65 boolean createFullPath = true;
66
67 RemoteOperationResult result = mActivity.createFolder(remotePath, createFullPath);
68 assertTrue(result.isSuccess() || result.getCode() == ResultCode.TIMEOUT);
69
70 // Create Subfolder
71 remotePath = "/testCreateFolder" + mCurrentDate + "/" + "testCreateFolder" + mCurrentDate;
72 createFullPath = true;
73
74 result = mActivity.createFolder(remotePath, createFullPath);
75 assertTrue(result.isSuccess() || result.getCode() == ResultCode.TIMEOUT);
76 }
77
78
79 /**
80 * Test to Create Folder with special characters: / \ < > : " | ? *
81 */
82 public void testCreateFolderSpecialCharacters() {
83 boolean createFullPath = true;
84
85 String remotePath = "/testSpecialCharacters_\\" + mCurrentDate;
86 RemoteOperationResult result = mActivity.createFolder(remotePath, createFullPath);
87 assertTrue(result.getCode() == ResultCode.INVALID_CHARACTER_IN_NAME);
88
89 remotePath = "/testSpecialCharacters_<" + mCurrentDate;
90 result = mActivity.createFolder(remotePath, createFullPath);
91 assertTrue(result.getCode() == ResultCode.INVALID_CHARACTER_IN_NAME);
92
93 remotePath = "/testSpecialCharacters_>" + mCurrentDate;
94 result = mActivity.createFolder(remotePath, createFullPath);
95 assertTrue(result.getCode() == ResultCode.INVALID_CHARACTER_IN_NAME);
96
97 remotePath = "/testSpecialCharacters_:" + mCurrentDate;
98 result = mActivity.createFolder(remotePath, createFullPath);
99 assertTrue(result.getCode() == ResultCode.INVALID_CHARACTER_IN_NAME);
100
101 remotePath = "/testSpecialCharacters_\"" + mCurrentDate;
102 result = mActivity.createFolder(remotePath, createFullPath);
103 assertTrue(result.getCode() == ResultCode.INVALID_CHARACTER_IN_NAME);
104
105 remotePath = "/testSpecialCharacters_|" + mCurrentDate;
106 result = mActivity.createFolder(remotePath, createFullPath);
107 assertTrue(result.getCode() == ResultCode.INVALID_CHARACTER_IN_NAME);
108
109 remotePath = "/testSpecialCharacters_?" + mCurrentDate;
110 result = mActivity.createFolder(remotePath, createFullPath);
111 assertTrue(result.getCode() == ResultCode.INVALID_CHARACTER_IN_NAME);
112
113 remotePath = "/testSpecialCharacters_*" + mCurrentDate;
114 result = mActivity.createFolder(remotePath, createFullPath);
115 assertTrue(result.getCode() == ResultCode.INVALID_CHARACTER_IN_NAME);
116 }
117
118
119 }