Java tutorial
/** * 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; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; import java.util.ArrayList; import java.util.HashMap; import java.util.Iterator; import java.util.List; import java.util.Map; import org.apache.http.HttpHeaders; import org.apache.http.HttpStatus; import org.junit.Ignore; import org.junit.Test; import org.junit.experimental.categories.Category; import org.junit.runner.RunWith; import org.w3c.dom.Document; import org.w3c.dom.Element; import org.w3c.dom.NamedNodeMap; import org.w3c.dom.Node; import org.w3c.dom.NodeList; import com.fujitsu.dc.core.DcCoreException; import com.fujitsu.dc.core.model.Box; 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.DcRunner; import com.fujitsu.dc.test.jersey.box.odatacol.schema.complextype.ComplexTypeUtils; import com.fujitsu.dc.test.jersey.box.odatacol.schema.complextypeproperty.ComplexTypePropertyUtils; import com.fujitsu.dc.test.setup.Setup; import com.fujitsu.dc.test.unit.core.UrlUtils; import com.fujitsu.dc.test.utils.AccountUtils; import com.fujitsu.dc.test.utils.BoxUtils; import com.fujitsu.dc.test.utils.CellUtils; import com.fujitsu.dc.test.utils.DavResourceUtils; import com.fujitsu.dc.test.utils.Http; import com.fujitsu.dc.test.utils.ResourceUtils; import com.fujitsu.dc.test.utils.RoleUtils; import com.fujitsu.dc.test.utils.TResponse; import com.fujitsu.dc.test.utils.TestMethodUtils; import com.sun.jersey.test.framework.JerseyTest; /** * MKCOL?. */ @RunWith(DcRunner.class) @Category({ Unit.class, Integration.class, Regression.class }) public class CollectionTest extends JerseyTest { /** * . */ public CollectionTest() { super("com.fujitsu.dc.core.rs"); } static final String ACL_AUTH_TEST_SETTING_FILE = "box/acl-authtest.txt"; static final String ACL_AUTH_PROPPATCH_TEST_SETTING_FILE = "box/acl-authtestProppatch.txt"; static final String TOKEN = AbstractCase.MASTER_TOKEN_NAME; static final String ACL_SETTING_TEST = "box/acl-setting.txt"; /** * MKCOL-Normal?. */ @Test public final void MKCOL_Normal?() { String path = "davcol1"; try { // ?? Http.request("box/mkcol-normal.txt") .with("cellPath", "testcell1") .with("path", path) .with("token", TOKEN) .returns() .statusCode(HttpStatus.SC_CREATED); // ??body? TResponse tresponseAll = Http.request("box/propfind-col-allprop.txt") .with("path", path) .with("depth", "0") .with("token", TOKEN) .returns(); tresponseAll.statusCode(HttpStatus.SC_MULTI_STATUS); // ??(body??) TResponse tresponse = Http.request("box/propfind-col-body-0.txt") .with("path", path) .with("depth", "0") .with("token", TOKEN) .returns(); tresponse.statusCode(HttpStatus.SC_MULTI_STATUS); // body? assertEquals(tresponse.getBody(), tresponseAll.getBody()); // BodyXML???? String status1 = getXmlNodeValue(tresponse.bodyAsXml(), "status"); assertEquals("HTTP/1.1 200 OK", status1); // webDAV???? assertNotNull(getXmlNodeValue(tresponse.bodyAsXml(), "response")); assertNotNull(getXmlNodeValue(tresponse.bodyAsXml(), "href")); assertNotNull(getXmlNodeValue(tresponse.bodyAsXml(), "propstat")); assertNotNull(getXmlNodeValue(tresponse.bodyAsXml(), "prop")); assertNotNull(getXmlNodeValue(tresponse.bodyAsXml(), "creationdate")); assertNotNull(getXmlNodeValue(tresponse.bodyAsXml(), "getlastmodified")); assertNotNull(getXmlNodeValue(tresponse.bodyAsXml(), "resourcetype")); } finally { // ? deleteTest(path, -1); // ???? Http.request("box/propfind-col-allprop.txt") .with("path", path) .with("depth", "0") .with("token", TOKEN) .returns() .statusCode(HttpStatus.SC_NOT_FOUND); } } /** * MKCOL_Body?. */ @Test public final void MKCOL_Body?() { String path = "davcol3"; StringBuilder sb; sb = new StringBuilder(); sb.append("<?xml version=\"1.0\" encoding=\"utf-8\"?>"); sb.append("<D:mkcol xmlns:D=\"DAV:\" xmlns:dc=\"urn:x-dc1:xmlns\">"); sb.append("<D:sets><D:prop><D:resourcetype><D:collection/></D:resourcetype></D:prop></D:sets>"); sb.append("</D:mkcol>"); // Http http = Http.request("box/mkcol-custom.txt").with("path", path).with("token", TOKEN); try { // XML? String code = DcCoreException.Dav.XML_ERROR.getCode(); String message = DcCoreException.Dav.XML_ERROR.getMessage(); sb = new StringBuilder(); sb.append("<?xml version=\"1.0\" encoding=\"utf-8\"?>"); sb.append("<D:mkcol xmlns:D=\"DAV:\" xmlns:dc=\"urn:x-dc1:xmlns\">"); sb.append("<D:set<D:prop><D:resourcetype2><D:collection/></D:resourcetype2></D:prop></D:set>"); sb.append("</D:mkcol>"); Http.request("box/mkcol-custom.txt") .with("path", path) .with("token", TOKEN) .with("body", sb.toString()) .returns() .statusCode(HttpStatus.SC_BAD_REQUEST) .checkErrorResponse(code, message); // set ?? sb = new StringBuilder(); sb.append("<?xml version=\"1.0\" encoding=\"utf-8\"?>"); sb.append("<D:mkcol xmlns:D=\"DAV:\" xmlns:dc=\"urn:x-dc1:xmlns\">"); sb.append("</D:mkcol>"); Http.request("box/mkcol-custom.txt") .with("path", path) .with("token", TOKEN) .with("body", sb.toString()) .returns() .statusCode(HttpStatus.SC_FORBIDDEN); // set ??? sb = new StringBuilder(); sb.append("<?xml version=\"1.0\" encoding=\"utf-8\"?>"); sb.append("<D:mkcol xmlns:D=\"DAV:\" xmlns:dc=\"urn:x-dc1:xmlns\">"); sb.append("<D:sets><D:prop><D:resourcetype><D:collection/></D:resourcetype></D:prop></D:sets>"); sb.append("</D:mkcol>"); Http.request("box/mkcol-custom.txt") .with("path", path) .with("token", TOKEN) .with("body", sb.toString()) .returns() .statusCode(HttpStatus.SC_FORBIDDEN); // props ??? sb = new StringBuilder(); sb.append("<?xml version=\"1.0\" encoding=\"utf-8\"?>"); sb.append("<D:mkcol xmlns:D=\"DAV:\" xmlns:dc=\"urn:x-dc1:xmlns\">"); sb.append("<D:set><D:props><D:resourcetype><D:collection/></D:resourcetype></D:props></D:set>"); sb.append("</D:mkcol>"); Http.request("box/mkcol-custom.txt") .with("path", path) .with("token", TOKEN) .with("body", sb.toString()) .returns() .statusCode(HttpStatus.SC_FORBIDDEN); // resourcetype ??? sb = new StringBuilder(); sb.append("<?xml version=\"1.0\" encoding=\"utf-8\"?>"); sb.append("<D:mkcol xmlns:D=\"DAV:\" xmlns:dc=\"urn:x-dc1:xmlns\">"); sb.append("<D:set><D:prop><D:resourcetype2><D:collection/></D:resourcetype2></D:prop></D:set>"); sb.append("</D:mkcol>"); Http.request("box/mkcol-custom.txt") .with("path", path) .with("token", TOKEN) .with("body", sb.toString()) .returns() .statusCode(HttpStatus.SC_FORBIDDEN); // resourcetype ?? sb = new StringBuilder(); sb.append("<?xml version=\"1.0\" encoding=\"utf-8\"?>"); sb.append("<D:mkcol xmlns:D=\"DAV:\" xmlns:dc=\"urn:x-dc1:xmlns\">"); sb.append("<D:set><D:prop><D:resourcetype><D:collection2/></D:resourcetype></D:prop></D:set>"); sb.append("</D:mkcol>"); Http.request("box/mkcol-custom.txt") .with("path", path) .with("token", TOKEN) .with("body", sb.toString()) .returns() .statusCode(HttpStatus.SC_FORBIDDEN); } catch (Exception e) { e.printStackTrace(); } finally { // ? deleteTest(path, -1); } } /** * mkcol?. */ @Test public final void MKCOL_Body??() { String path = "davcol2"; try { // ?? Http.request("box/mkcol-0.txt") .with("path", path) .with("token", TOKEN) .returns() .statusCode(HttpStatus.SC_CREATED); // ??(body??) TResponse tresponse = Http.request("box/propfind-col-body-0.txt") .with("path", path) .with("depth", "0") .with("token", TOKEN) .returns(); tresponse.statusCode(HttpStatus.SC_MULTI_STATUS); // ??body? TResponse tresponseAll = Http.request("box/propfind-col-allprop.txt") .with("path", path) .with("depth", "0") .with("token", TOKEN) .returns(); tresponseAll.statusCode(HttpStatus.SC_MULTI_STATUS); // propfind? assertEquals(tresponse.getBody(), tresponseAll.getBody()); // BodyXML???? String status1 = getXmlNodeValue(tresponse.bodyAsXml(), "status"); assertEquals("HTTP/1.1 200 OK", status1); // webDAV???? assertNotNull(getXmlNodeValue(tresponse.bodyAsXml(), "response")); assertNotNull(getXmlNodeValue(tresponse.bodyAsXml(), "href")); assertNotNull(getXmlNodeValue(tresponse.bodyAsXml(), "propstat")); assertNotNull(getXmlNodeValue(tresponse.bodyAsXml(), "prop")); assertNotNull(getXmlNodeValue(tresponse.bodyAsXml(), "creationdate")); assertNotNull(getXmlNodeValue(tresponse.bodyAsXml(), "getlastmodified")); assertNotNull(getXmlNodeValue(tresponse.bodyAsXml(), "resourcetype")); } finally { // ? deleteTest(path, -1); // ???? Http.request("box/propfind-col-allprop.txt") .with("path", path) .with("depth", "0") .with("token", TOKEN) .returns() .statusCode(HttpStatus.SC_NOT_FOUND); } } /** * mkcol?. */ @Test public final void MKCOL_Body?ContentLength??() { String path = "davcol2"; try { // ?? Http.request("box/mkcol-0-non-content-length.txt") .with("path", path) .with("token", TOKEN) .returns() .statusCode(HttpStatus.SC_CREATED); // ??(body??) TResponse tresponse = Http.request("box/propfind-col-body-0.txt") .with("path", path) .with("depth", "0") .with("token", TOKEN) .returns(); tresponse.statusCode(HttpStatus.SC_MULTI_STATUS); // ??body? TResponse tresponseAll = Http.request("box/propfind-col-allprop.txt") .with("path", path) .with("depth", "0") .with("token", TOKEN) .returns(); tresponseAll.statusCode(HttpStatus.SC_MULTI_STATUS); // propfind? assertEquals(tresponse.getBody(), tresponseAll.getBody()); // BodyXML???? String status1 = getXmlNodeValue(tresponse.bodyAsXml(), "status"); assertEquals("HTTP/1.1 200 OK", status1); // webDAV???? assertNotNull(getXmlNodeValue(tresponse.bodyAsXml(), "response")); assertNotNull(getXmlNodeValue(tresponse.bodyAsXml(), "href")); assertNotNull(getXmlNodeValue(tresponse.bodyAsXml(), "propstat")); assertNotNull(getXmlNodeValue(tresponse.bodyAsXml(), "prop")); assertNotNull(getXmlNodeValue(tresponse.bodyAsXml(), "creationdate")); assertNotNull(getXmlNodeValue(tresponse.bodyAsXml(), "getlastmodified")); assertNotNull(getXmlNodeValue(tresponse.bodyAsXml(), "resourcetype")); } finally { // ? deleteTest(path, -1); // ???? Http.request("box/propfind-col-allprop.txt") .with("path", path) .with("depth", "0") .with("token", TOKEN) .returns() .statusCode(HttpStatus.SC_NOT_FOUND); } } /** * OData??. */ @Test public final void OData??() { String path = "odatacol"; try { // ?? Http.request("box/mkcol-odata.txt") .with("cellPath", "testcell1") .with("boxPath", "box1") .with("path", path) .with("token", TOKEN) .returns() .statusCode(HttpStatus.SC_CREATED); // ??body? TResponse tresponseAll = Http.request("box/propfind-col-allprop.txt") .with("path", path) .with("depth", "0") .with("token", TOKEN) .returns(); tresponseAll.statusCode(HttpStatus.SC_MULTI_STATUS); // dc:odata ?? serviceColTypeTest(tresponseAll.bodyAsXml(), "dc:odata"); } finally { // Box? deleteTest(path, -1); } } /** * Service??. */ @Test public final void Service??() { String path = "servicecol"; try { // ?? Http.request("box/mkcol-service.txt") .with("cellPath", "testcell1") .with("path", path) .with("token", TOKEN) .returns() .statusCode(HttpStatus.SC_CREATED); // ??body? TResponse tresponseAll = Http.request("box/propfind-col-allprop.txt") .with("path", path) .with("depth", "0") .with("token", TOKEN) .returns(); tresponseAll.statusCode(HttpStatus.SC_MULTI_STATUS); // dc:service ?? serviceColTypeTest(tresponseAll.bodyAsXml(), "dc:service"); } finally { // ? deleteTest(path, -1); } } /** * Service??__src???????. */ @Test public final void Service??__src???????() { String path = "servicecol02"; try { // ?? Http.request("box/mkcol-service.txt").with("cellPath", Setup.TEST_CELL1).with("path", path) .with("token", TOKEN).returns().statusCode(HttpStatus.SC_CREATED); // ? deleteTest(path, HttpStatus.SC_NO_CONTENT); // servicecol02 ?? ResourceUtils.accessResource(path, TOKEN, HttpStatus.SC_NOT_FOUND, Setup.TEST_BOX1, Setup.TEST_CELL1); // __src ?? ResourceUtils.accessResource(path + "/__src", TOKEN, HttpStatus.SC_NOT_FOUND, Setup.TEST_BOX1, Setup.TEST_CELL1); } finally { // Box? deleteTest(path, -1); } } /** * ?. ? box1 davcol1 davcol2 davcol5 odatacol1 davcol3 => ????? servicecol1 davcol4 => * ????? */ @Test public final void ?() { try { // Dav?? Http.request("box/mkcol-normal.txt") .with("cellPath", "testcell1") .with("path", "davcol1") .with("token", TOKEN) .returns() .statusCode(HttpStatus.SC_CREATED); // ?? Dav??Dav??? Http.request("box/mkcol-normal.txt") .with("cellPath", "testcell1") .with("path", "davcol1/davcol2") .with("token", TOKEN) .returns() .statusCode(HttpStatus.SC_CREATED); // ?? Dav??Dav??? Http.request("box/mkcol-normal.txt") .with("cellPath", "testcell1") .with("path", "davcol1/davcol2/davcol5") .with("token", TOKEN) .returns() .statusCode(HttpStatus.SC_CREATED); // ?? Dav??OData??? Http.request("box/mkcol-odata.txt") .with("cellPath", "testcell1") .with("boxPath", "box1") .with("path", "davcol1/odatacol1") .with("token", TOKEN) .returns() .statusCode(HttpStatus.SC_CREATED); // ?? Dav??Service??? Http.request("box/mkcol-service.txt") .with("cellPath", "testcell1") .with("path", "davcol1/servicecol1") .with("token", TOKEN) .returns() .statusCode(HttpStatus.SC_CREATED); // ?? OData??????? // TODO ??404??????????? Http.request("box/mkcol-normal.txt") .with("cellPath", "testcell1") .with("path", "davcol1/odatacol1/davcol3") .with("token", TOKEN) .returns() .statusCode(HttpStatus.SC_NOT_FOUND); // ?? Service??????? // TODO ??404??????????? Http.request("box/mkcol-normal.txt") .with("cellPath", "testcell1") .with("path", "davcol1/servicecol1/davcol4") .with("token", TOKEN) .returns() .statusCode(HttpStatus.SC_METHOD_NOT_ALLOWED); // ??depth1? TResponse tresponseWebDav = Http.request("box/propfind-col-allprop.txt") .with("path", "davcol1") .with("depth", "1") .with("token", TOKEN) .returns(); tresponseWebDav.statusCode(HttpStatus.SC_MULTI_STATUS); // davcol1??XML?? String testcell = "testcell1"; String boxName = "box1"; String baseCell = "davcol1"; Element root = tresponseWebDav.bodyAsXml().getDocumentElement(); NodeList resourcetypeList = root.getElementsByTagName("response"); // response???4 assertEquals(4, resourcetypeList.getLength()); // ???hrefstatus?? depthTest(resourcetypeList, UrlUtils.box(testcell, boxName, baseCell), "HTTP/1.1 200 OK"); depthTest(resourcetypeList, UrlUtils.box(testcell, boxName, baseCell, "servicecol1"), "HTTP/1.1 200 OK"); depthTest(resourcetypeList, UrlUtils.box(testcell, boxName, baseCell, "odatacol1"), "HTTP/1.1 200 OK"); depthTest(resourcetypeList, UrlUtils.box(testcell, boxName, baseCell, "davcol2"), "HTTP/1.1 200 OK"); // davcol5???????? assertEquals(-1, tresponseWebDav.getBody().indexOf(UrlUtils.box(testcell, boxName, baseCell, "davcol2", "davcol5"))); } finally { // Box? deleteTest("davcol1/servicecol1", -1); deleteTest("davcol1/odatacol1", -1); deleteTest("davcol1/davcol2/davcol5", -1); deleteTest("davcol1/davcol2", -1); deleteTest("davcol1", -1); } } /** * DavCol???. ? box1 davcol1 davcol2 davFile.txt */ @Test public final void DavCol???() { String davCol1 = "davcol1"; String davCol2 = "davcol2"; String davFileName = "davFile.txt"; try { // Dav?? DavResourceUtils.createWebDavCollection(TOKEN, HttpStatus.SC_CREATED, davCol1); // ?? Dav??Dav??? DavResourceUtils.createWebDavCollection(TOKEN, HttpStatus.SC_CREATED, davCol1 + "/" + davCol2); // Dav?? DavResourceUtils.createWebDavFile(Setup.TEST_CELL1, TOKEN, "box/dav-put.txt", "hoge", Setup.TEST_BOX1, davCol1 + "/" + davCol2 + "/" + davFileName, HttpStatus.SC_CREATED); // ??DavFile??????? deleteTest(davCol1 + "/" + davCol2, HttpStatus.SC_CONFLICT); // ??davcol2??????? deleteTest(davCol1, HttpStatus.SC_CONFLICT); // Dav? DavResourceUtils.deleteWebDavFile("box/dav-delete.txt", Setup.TEST_CELL1, TOKEN, davCol1 + "/" + davCol2 + "/" + davFileName, HttpStatus.SC_NO_CONTENT, Setup.TEST_BOX1); // ??DavFile????????? deleteTest(davCol1 + "/" + davCol2, HttpStatus.SC_NO_CONTENT); // ??davcol2????? deleteTest(davCol1, HttpStatus.SC_NO_CONTENT); } finally { // ? DavResourceUtils.deleteWebDavFile("box/dav-delete.txt", Setup.TEST_CELL1, TOKEN, davCol1 + "/" + davCol2 + "/" + davFileName, -1, Setup.TEST_BOX1); deleteTest(davCol1 + "/" + davCol2, -1); deleteTest(davCol1, -1); } } /** * Box??Collection?. ? deleteBox davcol1 */ @Test public final void Box??Collection?() { String boxName = "deleteBox"; String davCol1 = "davcol1"; try { // Box?? BoxUtils.create(Setup.TEST_CELL1, boxName, TOKEN, HttpStatus.SC_CREATED); // ?? DavResourceUtils.createWebDavCollection("box/mkcol.txt", Setup.TEST_CELL1, boxName + "/" + davCol1, TOKEN, HttpStatus.SC_CREATED); // Box??davcol1??????? BoxUtils.delete(Setup.TEST_CELL1, TOKEN, boxName, HttpStatus.SC_CONFLICT); // ? DavResourceUtils.deleteCollection(Setup.TEST_CELL1, boxName, davCol1, TOKEN, HttpStatus.SC_NO_CONTENT); // ??davcol1????? BoxUtils.delete(Setup.TEST_CELL1, TOKEN, boxName, HttpStatus.SC_NO_CONTENT); } finally { // ? DavResourceUtils.deleteCollection(Setup.TEST_CELL1, boxName, davCol1, TOKEN, -1); BoxUtils.delete(Setup.TEST_CELL1, TOKEN, boxName, -1); } } /** * Box??WebDavFile?. ? deleteBox deleteFile */ @Test public final void Box??WebDavFile?() { String boxName = "deleteBox"; String davFileNmae = "deleteFile"; try { // Box?? BoxUtils.create(Setup.TEST_CELL1, boxName, TOKEN, HttpStatus.SC_CREATED); // Box?WebDav? DavResourceUtils.createWebDavFile(Setup.TEST_CELL1, TOKEN, "box/dav-put.txt", "hoge", boxName, davFileNmae, HttpStatus.SC_CREATED); // Box??deleteFile??????? BoxUtils.delete(Setup.TEST_CELL1, TOKEN, boxName, HttpStatus.SC_CONFLICT); // WebDav? DavResourceUtils.deleteWebDavFile(Setup.TEST_CELL1, TOKEN, boxName, davFileNmae); // Box??deleteFile????? BoxUtils.delete(Setup.TEST_CELL1, TOKEN, boxName, HttpStatus.SC_NO_CONTENT); } finally { // WebDav? DavResourceUtils.deleteWebDavFile(Setup.TEST_CELL1, TOKEN, boxName, davFileNmae); // Box? BoxUtils.delete(Setup.TEST_CELL1, TOKEN, boxName, -1); } } /** * Odata???. ? deleteOdata deleteEntType */ @Test public final void Odata???() { String odataName = "deleteOdata"; String entityType = "deleteEntType"; String accept = "application/xml"; try { // Odata?? DavResourceUtils.createODataCollection(TOKEN, HttpStatus.SC_CREATED, Setup.TEST_CELL1, Setup.TEST_BOX1, odataName); // EntityType?? Http.request("box/entitySet-post.txt") .with("cellPath", Setup.TEST_CELL1) .with("boxPath", Setup.TEST_BOX1) .with("odataSvcPath", odataName) .with("token", "Bearer " + TOKEN) .with("accept", accept) .with("Name", entityType) .returns() .statusCode(HttpStatus.SC_CREATED); // Odata??deleteEntType??????? TResponse response = deleteTest(odataName, HttpStatus.SC_FORBIDDEN); String code = DcCoreException.Dav.HAS_CHILDREN.getCode(); String message = DcCoreException.Dav.HAS_CHILDREN.getMessage(); response.checkErrorResponse(code, message); // EntityType? entityTypeDelete(odataName, TOKEN, accept, entityType, Setup.TEST_CELL1, HttpStatus.SC_NO_CONTENT); // Odata??deleteEntType????? deleteTest(odataName, HttpStatus.SC_NO_CONTENT); } finally { // EntityType? entityTypeDelete(odataName, TOKEN, accept, entityType, Setup.TEST_CELL1, -1); // Odata? deleteTest(odataName, -1); } } /** * Odata???. ? deleteOdata deleteComplexType deleteComplexTypeProperty */ @Test public final void Odata?Complex??() { String odataName = "deleteOdata"; String complexTypeName = "deleteComplexType"; String complexTypePropertyName = "deleteComplexTypeProperty"; try { // Odata?? DavResourceUtils.createODataCollection(TOKEN, HttpStatus.SC_CREATED, Setup.TEST_CELL1, Setup.TEST_BOX1, odataName); // ComplexType?? ComplexTypeUtils.create(Setup.TEST_CELL1, Setup.TEST_BOX1, odataName, complexTypeName, HttpStatus.SC_CREATED); // Odata??ComplexType??????? TResponse response = deleteTest(odataName, HttpStatus.SC_FORBIDDEN); String code = DcCoreException.Dav.HAS_CHILDREN.getCode(); String message = DcCoreException.Dav.HAS_CHILDREN.getMessage(); response.checkErrorResponse(code, message); // ComplexTypeProperty?? ComplexTypePropertyUtils.create(Setup.TEST_CELL1, Setup.TEST_BOX1, odataName, complexTypePropertyName, complexTypeName, "Edm.String", HttpStatus.SC_CREATED); // Odata??ComplexType + ComplexTypeProeprty??????? response = deleteTest(odataName, HttpStatus.SC_FORBIDDEN); code = DcCoreException.Dav.HAS_CHILDREN.getCode(); message = DcCoreException.Dav.HAS_CHILDREN.getMessage(); response.checkErrorResponse(code, message); // ComplexTypeProperty? ComplexTypePropertyUtils.delete(Setup.TEST_CELL1, Setup.TEST_BOX1, odataName, complexTypePropertyName, complexTypeName, HttpStatus.SC_NO_CONTENT); // ComplexType? ComplexTypeUtils.delete(AbstractCase.MASTER_TOKEN_NAME, Setup.TEST_CELL1, Setup.TEST_BOX1, odataName, complexTypeName, HttpStatus.SC_NO_CONTENT); // Odata??ComplexType + ComplexTypeProeprty????? deleteTest(odataName, HttpStatus.SC_NO_CONTENT); } finally { // ComplexTypeProperty? ComplexTypePropertyUtils.delete(Setup.TEST_CELL1, Setup.TEST_BOX1, odataName, complexTypePropertyName, complexTypeName, -1); // ComplexType? ComplexTypeUtils.delete(AbstractCase.MASTER_TOKEN_NAME, Setup.TEST_CELL1, Setup.TEST_BOX1, odataName, complexTypeName, -1); // Odata? deleteTest(odataName, -1); } } /** * Service???. ? deleteService __src davFile.txt */ @Test public final void Service???() { String sriveceName = "deleteService"; String src = "__src"; String davFileName = "davFile.js"; try { // service?? DavResourceUtils.createServiceCollection(TOKEN, HttpStatus.SC_CREATED, sriveceName); // ?? DavResourceUtils.createWebDavFile(Setup.TEST_CELL1, TOKEN, "box/dav-put.txt", "hoge", Setup.TEST_BOX1, sriveceName + "/" + src + "/" + davFileName, HttpStatus.SC_CREATED); // service??__src/davFile.js??????? TResponse response = deleteTest(sriveceName, HttpStatus.SC_FORBIDDEN); String code = DcCoreException.Dav.HAS_CHILDREN.getCode(); String message = DcCoreException.Dav.HAS_CHILDREN.getMessage(); response.checkErrorResponse(code, message); // ? DavResourceUtils.deleteWebDavFile("box/dav-delete.txt", Setup.TEST_CELL1, TOKEN, sriveceName + "/" + src + "/" + davFileName, HttpStatus.SC_NO_CONTENT, Setup.TEST_BOX1); // service??__src/davFile.js????? deleteTest(sriveceName, HttpStatus.SC_NO_CONTENT); } finally { // ? DavResourceUtils.deleteWebDavFile("box/dav-delete.txt", Setup.TEST_CELL1, TOKEN, sriveceName + "/" + src + "/" + davFileName, -1, Setup.TEST_BOX1); // service? deleteTest(sriveceName, -1); } } /** * DELETE?. * @return DELETE?? */ private TResponse deleteTest(final String path, int code) { // ? return Http.request("box/delete-col.txt") .with("cellPath", "testcell1") .with("path", path) .with("token", TOKEN) .returns() .statusCode(code); } /** * resourcetype?. resourcetype??=1 resourcetype?=1 collectionserviceType?? */ private void serviceColTypeTest(final Document doc, final String serviceType) { Element root = doc.getDocumentElement(); NodeList resourcetypeList = root.getElementsByTagName("resourcetype"); assertEquals(1, resourcetypeList.getLength()); Element resourcetype = (Element) resourcetypeList.item(0); NodeList children = resourcetype.getChildNodes(); String dc = null; String collection = null; int elementCounut = 0; for (int i = 0; i < children.getLength(); i++) { Node child = children.item(i); if (child instanceof Element) { elementCounut++; Element childElement = (Element) child; if (childElement.getTagName().equals(serviceType)) { dc = childElement.getTagName(); } else if (childElement.getTagName().equals("collection")) { collection = childElement.getTagName(); } } } assertEquals(2, elementCounut); assertNotNull(dc); assertNotNull(collection); } /** * depth:1??PROPFIND??body. */ private void depthTest(final NodeList nodeList, final String resorce, final String statusLine) { String statusResult = ""; Element resourcetype = null; for (int c = 0; c < nodeList.getLength(); c++) { resourcetype = (Element) nodeList.item(c); NodeList hrefchildren = resourcetype.getElementsByTagName("href"); assertNotNull(hrefchildren); assertEquals(1, hrefchildren.getLength()); String hrefResult = (hrefchildren.item(0)).getFirstChild().getNodeValue(); if (hrefResult.equals(resorce)) { NodeList statuschild = resourcetype.getElementsByTagName("status"); assertNotNull(statuschild); assertEquals(1, statuschild.getLength()); statusResult = (statuschild.item(0)).getFirstChild().getNodeValue(); break; } } assertEquals(statusResult, statusLine); } /** * Depth?. */ @Test public final void Depth??() { String path = "depthcol"; try { // ?? Http.request("box/mkcol-normal.txt") .with("cellPath", "testcell1") .with("path", path) .with("token", TOKEN) .returns() .statusCode(HttpStatus.SC_CREATED); // ??(depth:infinity) Http.request("box/propfind-col-allprop.txt") .with("path", path) .with("depth", "infinity") .with("token", TOKEN) .returns() .statusCode(HttpStatus.SC_FORBIDDEN); // ??(depth:error) Http.request("box/propfind-col-allprop.txt") .with("path", path) .with("depth", "error") .with("token", TOKEN) .returns() .statusCode(HttpStatus.SC_BAD_REQUEST); // ??(depth:null) Http.request("box/propfind-col-allprop-depth-null.txt") .with("path", path) .with("token", TOKEN) .returns() .statusCode(HttpStatus.SC_BAD_REQUEST); } finally { deleteTest(path, -1); } } /** * PROPPATCH?. =>=> */ @Test public final void PROPPATCH?() { String path = "patchcol"; String testcell = "testcell1"; String boxName = "box1"; try { TResponse tresponseWebDav = null; // DAV?? tresponseWebDav = Http.request("box/mkcol-normal.txt") .with("cellPath", "testcell1") .with("path", path) .with("token", TOKEN) .returns() .statusCode(HttpStatus.SC_CREATED); String etag1 = tresponseWebDav.getHeader(HttpHeaders.ETAG); assertNotNull(etag1); // PROPPATCH tresponseWebDav = Http.request("box/proppatch-set.txt").with("cell", testcell).with("box", boxName) .with("path", path).with("token", TOKEN) .with("author1", "Test User1") .with("hoge", "hoge") .returns(); tresponseWebDav.statusCode(HttpStatus.SC_MULTI_STATUS); String etag2 = tresponseWebDav.getHeader(HttpHeaders.ETAG); assertNotNull(etag2); assertFalse(etag1.equals(etag2)); // ?? tresponseWebDav = Http.request("box/propfind-col-allprop.txt").with("path", path).with("token", TOKEN) .with("depth", "0") .returns(); tresponseWebDav.statusCode(HttpStatus.SC_MULTI_STATUS); Element root = tresponseWebDav.bodyAsXml().getDocumentElement(); String resorce = UrlUtils.box(testcell, boxName, path); HashMap<String, String> map = new HashMap<String, String>(); // TODO ????? map.put("Author", "Test User1"); map.put("hoge", "hoge"); proppatchResponseTest(root, resorce, map); // ? tresponseWebDav = Http.request("box/proppatch-set.txt").with("cell", testcell).with("box", boxName) .with("path", path).with("token", TOKEN) .with("author1", "Author1 update") .with("hoge", "fuga") .returns(); tresponseWebDav.statusCode(HttpStatus.SC_MULTI_STATUS); // ?? tresponseWebDav = Http.request("box/propfind-col-allprop.txt").with("path", path).with("token", TOKEN) .with("depth", "0") .returns(); tresponseWebDav.statusCode(HttpStatus.SC_MULTI_STATUS); Element root2 = tresponseWebDav.bodyAsXml().getDocumentElement(); HashMap<String, String> map2 = new HashMap<String, String>(); map.put("Author", "Author1 update"); map.put("hoge", "fuga"); proppatchResponseTest(root2, resorce, map2); // ? tresponseWebDav = Http.request("box/proppatch-remove.txt").with("path", path).with("token", TOKEN) .returns(); tresponseWebDav.statusCode(HttpStatus.SC_MULTI_STATUS); // ?? tresponseWebDav = Http.request("box/propfind-col-allprop.txt").with("path", path).with("token", TOKEN) .with("depth", "0") .returns(); tresponseWebDav.statusCode(HttpStatus.SC_MULTI_STATUS); Element root3 = tresponseWebDav.bodyAsXml().getDocumentElement(); HashMap<String, String> map3 = new HashMap<String, String>(); map.put("Author", null); map.put("hoge", null); proppatchResponseTest(root3, resorce, map3); // set?remove?? // TODO SET?REMOVE??????set?remove????PROPSTAT????????????? // TODO SET??????????????? <key>value</key> => <key/> tresponseWebDav = Http.request("box/proppatch.txt").with("cell", Setup.TEST_CELL1) .with("box", Setup.TEST_BOX1).with("path", path).with("token", "Bearer " + TOKEN) .with("author1", "Author1 update").with("hoge", "fuga") .returns(); tresponseWebDav.statusCode(HttpStatus.SC_MULTI_STATUS); tresponseWebDav = Http.request("box/propfind-col-allprop.txt").with("path", path).with("token", TOKEN) .with("depth", "0") .returns(); tresponseWebDav.statusCode(HttpStatus.SC_MULTI_STATUS); } finally { deleteTest(path, -1); } } /** * PROPPATCH?. =>=> */ @Test public final void PROPPATCH ?() { String path = "patchclasscol"; String testcell = "testcell1"; String boxName = "box1"; try { TResponse tresponseWebDav = null; // DAV?? Http.request("box/mkcol-normal.txt") .with("cellPath", "testcell1") .with("path", path) .with("token", TOKEN) .returns() .statusCode(HttpStatus.SC_CREATED); // PROPPATCH tresponseWebDav = Http.request("box/proppatch-class.txt").with("path", path).with("token", TOKEN) .with("cellPath", "testcell1") .with("name1", "Test User1") .with("src1", "hoge") .with("name2", "Test User2") .with("src2", "fuga") .with("name3", "Test User3") .with("src3", "boy") .returns(); tresponseWebDav.statusCode(HttpStatus.SC_MULTI_STATUS); // ?? tresponseWebDav = Http.request("box/propfind-col-allprop.txt").with("path", path).with("token", TOKEN) .with("depth", "0") .returns(); tresponseWebDav.statusCode(HttpStatus.SC_MULTI_STATUS); Element root = tresponseWebDav.bodyAsXml().getDocumentElement(); String resorce = UrlUtils.box(testcell, boxName, path); ArrayList<String> list = new ArrayList<String>(); // TODO ????? list.add("name"); list.add("Test User1"); list.add("src"); list.add("hoge"); list.add("name"); list.add("Test User2"); list.add("src"); list.add("fuga"); list.add("name"); list.add("Test User3"); list.add("src"); list.add("boy"); proppatchClassResponseTest(root, resorce, "service", list); // ? tresponseWebDav = Http.request("box/proppatch-class.txt").with("path", path).with("token", TOKEN) .with("cellPath", "testcell1") .with("name1", "Test User13") .with("src1", "hoge3") .with("name2", "Test User23") .with("src2", "3fuga") .with("name3", "3Test User3") .with("src3", "3boy") .returns(); tresponseWebDav.statusCode(HttpStatus.SC_MULTI_STATUS); // ?? tresponseWebDav = Http.request("box/propfind-col-allprop.txt").with("path", path).with("token", TOKEN) .with("depth", "0") .returns(); tresponseWebDav.statusCode(HttpStatus.SC_MULTI_STATUS); Element root2 = tresponseWebDav.bodyAsXml().getDocumentElement(); ArrayList<String> list2 = new ArrayList<String>(); list2.add("name"); list2.add("Test User13"); list2.add("src"); list2.add("hoge3"); list2.add("name"); list2.add("Test User23"); list2.add("src"); list2.add("3fuga"); list2.add("name"); list2.add("3Test User3"); list2.add("src"); list2.add("3boy"); proppatchClassResponseTest(root2, resorce, "service", list2); // ? tresponseWebDav = Http.request("box/proppatch-remove.txt").with("path", path).with("token", TOKEN) .returns(); tresponseWebDav.statusCode(HttpStatus.SC_MULTI_STATUS); } finally { deleteTest(path, -1); } } /** * WebDAV_ACL?. */ @Test public final void WebDAV_ACL?() { String path = "aclcol1"; String testcell = "testcell1"; String boxName = "box1"; try { // ?? Http.request("box/mkcol-normal.txt") .with("cellPath", "testcell1") .with("path", path) .with("token", TOKEN) .returns() .statusCode(HttpStatus.SC_CREATED); // ACL? Http.request("box/acl.txt") .with("colname", path) .with("token", TOKEN) .with("roleBaseUrl", UrlUtils.roleResource(testcell, null, "")) .with("level", "") .returns() .statusCode(HttpStatus.SC_OK); // ACL?? TResponse tresponseWebDav = Http.request("box/propfind-col-allprop.txt") .with("path", path) .with("depth", "1") .with("token", TOKEN) .returns(); tresponseWebDav.statusCode(HttpStatus.SC_MULTI_STATUS); // PROPFOIND??? String resorce = UrlUtils.box(testcell, boxName, path); Element root2 = tresponseWebDav.bodyAsXml().getDocumentElement(); List<Map<String, List<String>>> list = new ArrayList<Map<String, List<String>>>(); Map<String, List<String>> map = new HashMap<String, List<String>>(); List<String> rolList = new ArrayList<String>(); rolList.add("read"); rolList.add("write"); map.put(UrlUtils.aclRelativePath(Box.DEFAULT_BOX_NAME, "role1"), rolList); list.add(map); List<String> rolList2 = new ArrayList<String>(); Map<String, List<String>> map2 = new HashMap<String, List<String>>(); rolList2.add("read"); map2.put(UrlUtils.aclRelativePath(Box.DEFAULT_BOX_NAME, "role2"), rolList2); list.add(map2); TestMethodUtils.aclResponseTest(root2, resorce, list, 1, UrlUtils.roleResource(testcell, boxName, ""), null); } finally { deleteTest(path, -1); } } /** * WebDAV_ACL?Pricipal?. */ @Test public final void WebDAV_ACL?Pricipal?() { String path = "aclcol1"; String testcell = "testcell1"; String boxName = "box1"; try { // ?? DavResourceUtils.createWebDavCollection("box/mkcol-normal.txt", testcell, path, TOKEN, HttpStatus.SC_CREATED); // ACL? DavResourceUtils.setACLwithRoleBaseUrl(testcell, TOKEN, HttpStatus.SC_OK, boxName, path, "box/acl-setting-baseurl.txt", UrlUtils.roleResource(testcell, null, "role1"), "<D:read/>", ""); // ACL?? TResponse tresponseWebDav = DavResourceUtils.propfind("box/propfind-col-allprop.txt", TOKEN, HttpStatus.SC_MULTI_STATUS, path); // PROPFOIND??? String resorce = UrlUtils.box(testcell, boxName, path); Element root2 = tresponseWebDav.bodyAsXml().getDocumentElement(); List<Map<String, List<String>>> list = new ArrayList<Map<String, List<String>>>(); Map<String, List<String>> map = new HashMap<String, List<String>>(); List<String> rolList = new ArrayList<String>(); rolList.add("read"); map.put(UrlUtils.aclRelativePath(Box.DEFAULT_BOX_NAME, "role1"), rolList); list.add(map); TestMethodUtils.aclResponseTest(root2, resorce, list, 1, UrlUtils.roleResource(testcell, boxName, ""), null); } finally { deleteTest(path, -1); } } /** * Service_ACL?. */ @Test public final void Service_ACL?() { String path = "aclcol1"; String testcell = "testcell1"; String boxName = "box1"; try { // ?? Http.request("box/mkcol-service.txt") .with("cellPath", "testcell1") .with("path", path) .with("token", TOKEN) .returns() .statusCode(HttpStatus.SC_CREATED); // ACL? Http.request("box/acl-service.txt") .with("colname", path) .with("token", TOKEN) .with("roleBaseUrl", UrlUtils.roleResource(testcell, null, "")) .with("level", "") .returns() .statusCode(HttpStatus.SC_OK); // ACL?? TResponse tresponseWebDav = Http.request("box/propfind-col-allprop.txt") .with("path", path) .with("depth", "1") .with("token", TOKEN) .returns(); tresponseWebDav.statusCode(HttpStatus.SC_MULTI_STATUS); // PROPFOIND??? String resorce = UrlUtils.box(testcell, boxName, path); Element root2 = tresponseWebDav.bodyAsXml().getDocumentElement(); List<Map<String, List<String>>> list = new ArrayList<Map<String, List<String>>>(); Map<String, List<String>> map = new HashMap<String, List<String>>(); List<String> rolList = new ArrayList<String>(); rolList.add("exec"); map.put(UrlUtils.aclRelativePath(Box.DEFAULT_BOX_NAME, "role1"), rolList); list.add(map); TestMethodUtils.aclResponseTest(root2, resorce, list, 2, UrlUtils.roleResource(testcell, boxName, ""), null); } finally { deleteTest(path, -1); } } /** * OData_ACL?. */ @Test public final void OData_ACL?() { String path = "aclcol1"; String testcell = "testcell1"; String boxName = "box1"; try { // ?? Http.request("box/mkcol-odata.txt") .with("cellPath", "testcell1") .with("boxPath", "box1") .with("path", path) .with("token", TOKEN) .returns() .statusCode(HttpStatus.SC_CREATED); // ACL? Http.request("box/acl.txt") .with("colname", path) .with("token", TOKEN) .with("roleBaseUrl", UrlUtils.roleResource(testcell, null, "")) .with("level", "") .returns() .statusCode(HttpStatus.SC_OK); // ACL?? TResponse tresponseWebDav = Http.request("box/propfind-col-allprop.txt") .with("path", path) .with("depth", "1") .with("token", TOKEN) .returns(); tresponseWebDav.statusCode(HttpStatus.SC_MULTI_STATUS); // PROPFOIND??? String resorce = UrlUtils.box(testcell, boxName, path); Element root2 = tresponseWebDav.bodyAsXml().getDocumentElement(); List<Map<String, List<String>>> list = new ArrayList<Map<String, List<String>>>(); Map<String, List<String>> map = new HashMap<String, List<String>>(); List<String> rolList = new ArrayList<String>(); rolList.add("read"); rolList.add("write"); map.put(UrlUtils.aclRelativePath(Box.DEFAULT_BOX_NAME, "role1"), rolList); list.add(map); List<String> rolList2 = new ArrayList<String>(); Map<String, List<String>> map2 = new HashMap<String, List<String>>(); rolList2.add("read"); map2.put(UrlUtils.aclRelativePath(Box.DEFAULT_BOX_NAME, "role2"), rolList2); list.add(map2); TestMethodUtils.aclResponseTest(root2, resorce, list, 1, UrlUtils.roleResource(testcell, boxName, ""), null); } finally { deleteTest(path, -1); } } /** * ROLE???????ACL?. */ @Test public final void ROLE???????ACL?() { String path = "setodata"; String testcell = "testcell1"; // ACL? Http.request("box/acl-role-not-found.txt") .with("colname", path) .with("token", TOKEN) .with("roleBaseUrl", UrlUtils.roleResource(testcell, null, "")) .with("level", "") .returns() .statusCode(HttpStatus.SC_BAD_REQUEST); } /** * xml:base????Cell?????ACL?. */ @Test public final void xml_base????Cell?????ACL?() { // ACL? Http.request("box/acl-setting-single-collection.txt") .with("cell", Setup.TEST_CELL1) .with("box", Setup.TEST_BOX1) .with("col", Setup.TEST_ODATA) .with("token", AbstractCase.MASTER_TOKEN_NAME) .with("roleBaseUrl", UrlUtils.roleResource("notExistsCell", null, "role1")) .returns() .statusCode(HttpStatus.SC_BAD_REQUEST); } /** * xml_base????Box?????ACL?. */ @Test public final void xml_base????Box?????ACL?() { // ACL? Http.request("box/acl-setting-single-collection.txt") .with("cell", Setup.TEST_CELL1) .with("box", Setup.TEST_BOX1) .with("col", Setup.TEST_ODATA) .with("token", AbstractCase.MASTER_TOKEN_NAME) .with("roleBaseUrl", UrlUtils.roleResource(Setup.TEST_CELL1, "notExistsBox", "role1")) .with("level", "") .returns() .statusCode(HttpStatus.SC_BAD_REQUEST); } /** * xml_base????Collection?????ACL?. */ @Test public final void xml_base????Collection?????ACL?() { // ACL? Http.request("box/acl-setting-href-with-baseurl.txt") .with("cell", Setup.TEST_CELL1) .with("box", Setup.TEST_BOX1) .with("col", Setup.TEST_ODATA) .with("role", "notExistsCol/../__/role1") .with("token", AbstractCase.MASTER_TOKEN_NAME) .with("roleBaseUrl", UrlUtils.roleResource(Setup.TEST_CELL1, null, "")) .with("level", "") .returns() .statusCode(HttpStatus.SC_BAD_REQUEST); } /** * Role???????Box???????ACL?. */ @Test public final void Role???????Box???????ACL?() { String testBox = "testBox01"; String testRole = "testRole01"; try { // Box?? BoxUtils.create(Setup.TEST_CELL1, testBox, TOKEN); // Box?????Role?? RoleUtils.create(Setup.TEST_CELL1, TOKEN, null, testRole, HttpStatus.SC_CREATED); // ACL? Http.request("box/acl-setting-single-collection.txt") .with("cell", Setup.TEST_CELL1) .with("box", Setup.TEST_BOX1) .with("col", Setup.TEST_ODATA) .with("token", AbstractCase.MASTER_TOKEN_NAME) .with("roleBaseUrl", UrlUtils.roleResource(Setup.TEST_CELL1, testBox, testRole)) .with("level", "") .returns() .statusCode(HttpStatus.SC_BAD_REQUEST); } finally { // Role? RoleUtils.delete(Setup.TEST_CELL1, TOKEN, null, testRole); // Box1? BoxUtils.delete(Setup.TEST_CELL1, TOKEN, testBox); } } /** * BOX_ACL?. */ @Test public final void Box_ACL?() { String path = "box1"; String testcell = "testcell1"; try { // ACL? Http.request("box/acl.txt") .with("colname", "") .with("token", TOKEN) .with("roleBaseUrl", UrlUtils.roleResource(testcell, null, "")) .with("level", "") .returns() .statusCode(HttpStatus.SC_OK); // ACL?? TResponse tresponseWebDav = CellUtils.propfind(testcell + "/" + path, TOKEN, "0", HttpStatus.SC_MULTI_STATUS); // PROPFOIND??? String resorce = UrlUtils.boxRoot(testcell, path); Element root2 = tresponseWebDav.bodyAsXml().getDocumentElement(); List<Map<String, List<String>>> list = new ArrayList<Map<String, List<String>>>(); Map<String, List<String>> map = new HashMap<String, List<String>>(); List<String> rolList = new ArrayList<String>(); rolList.add("read"); rolList.add("write"); map.put(UrlUtils.aclRelativePath(Box.DEFAULT_BOX_NAME, "role1"), rolList); list.add(map); List<String> rolList2 = new ArrayList<String>(); Map<String, List<String>> map2 = new HashMap<String, List<String>>(); rolList2.add("read"); map2.put(UrlUtils.aclRelativePath(Box.DEFAULT_BOX_NAME, "role2"), rolList2); list.add(map2); TestMethodUtils.aclResponseTest(root2, resorce, list, 1, UrlUtils.roleResource(testcell, path, ""), null); } finally { // ACL??? DavResourceUtils.setACL(testcell, AbstractCase.MASTER_TOKEN_NAME, HttpStatus.SC_OK, "", ACL_AUTH_TEST_SETTING_FILE, Setup.TEST_BOX1, ""); } } /** * BOX_ACL_??Role??ACL???????. */ @Test public final void BOX_ACL_??Role??ACL???????() { String path = "box1"; String testcell = "testcell1"; String token = AbstractCase.MASTER_TOKEN_NAME; String[] roles = {"RoleName", "role-name" }; try { for (String role : roles) { try { // ? // ????? RoleUtils.create(testcell, token, path, role, HttpStatus.SC_CREATED); // ACL? DavResourceUtils.setACLwithBox(testcell, token, HttpStatus.SC_OK, path, "", "box/acl-setting.txt", role, path, "<D:write/>" , ""); // ACL?? TResponse tresponseWebDav = CellUtils.propfind(testcell + "/" + path, TOKEN, "0", HttpStatus.SC_MULTI_STATUS); // PROPFOIND??? String resorce = UrlUtils.boxRoot(testcell, path); Element root = tresponseWebDav.bodyAsXml().getDocumentElement(); List<Map<String, List<String>>> list = new ArrayList<Map<String, List<String>>>(); Map<String, List<String>> map = new HashMap<String, List<String>>(); List<String> rolList = new ArrayList<String>(); rolList.add("write"); map.put(role, rolList); list.add(map); TestMethodUtils.aclResponseTest(root, resorce, list, 1, UrlUtils.roleResource(testcell, path, ""), null); } finally { // Role RoleUtils.delete(testcell, token, path, role); } } } finally { // ACL?? DavResourceUtils.setACL(testcell, AbstractCase.MASTER_TOKEN_NAME, HttpStatus.SC_OK, "", ACL_AUTH_TEST_SETTING_FILE, Setup.TEST_BOX1, ""); } } /** * PropFind?PropPatch??. */ @Test public final void PropFind?PropPatch??() { final String accountRead = "accountRead"; final String accountReadAcl = "accountReadAcl"; final String testCol = "testCol"; try { // Account?? AccountUtils.create(AbstractCase.MASTER_TOKEN_NAME, Setup.TEST_CELL1, accountRead, accountRead, HttpStatus.SC_CREATED); AccountUtils.create(AbstractCase.MASTER_TOKEN_NAME, Setup.TEST_CELL1, accountReadAcl, accountReadAcl, HttpStatus.SC_CREATED); // Read RoleUtils.create(Setup.TEST_CELL1, AbstractCase.MASTER_TOKEN_NAME, null, "roleRead", HttpStatus.SC_CREATED); // Read-Acl RoleUtils.create(Setup.TEST_CELL1, AbstractCase.MASTER_TOKEN_NAME, null, "roleReadAcl", HttpStatus.SC_CREATED); // ????BOX???????????? ResourceUtils.linkAccountRole(Setup.TEST_CELL1, AbstractCase.MASTER_TOKEN_NAME, accountRead, null, "roleRead", HttpStatus.SC_NO_CONTENT); // ????BOX???????????? ResourceUtils.linkAccountRole(Setup.TEST_CELL1, AbstractCase.MASTER_TOKEN_NAME, accountReadAcl, null, "roleReadAcl", HttpStatus.SC_NO_CONTENT); // ? DavResourceUtils.createODataCollection(AbstractCase.MASTER_TOKEN_NAME, HttpStatus.SC_CREATED, Setup.TEST_CELL1, Setup.TEST_BOX1, testCol); // ACL DavResourceUtils.setACL(Setup.TEST_CELL1, AbstractCase.MASTER_TOKEN_NAME, HttpStatus.SC_OK, testCol, ACL_AUTH_PROPPATCH_TEST_SETTING_FILE, Setup.TEST_BOX1, ""); // ???? String readToken = ResourceUtils.getMyCellLocalToken(Setup.TEST_CELL1, accountRead, accountRead); // ???ACL?? String readAclToken = ResourceUtils.getMyCellLocalToken(Setup.TEST_CELL1, accountReadAcl, accountReadAcl); // PropFind TResponse res = DavResourceUtils.propfind("box/propfind-col-allprop.txt", readToken, HttpStatus.SC_MULTI_STATUS, testCol); // PROPFIND(XML?)?ACL????? // ACL?????? NodeList list = res.bodyAsXml().getElementsByTagNameNS("DAV:", "acl"); assertTrue(res.getBody(), list.getLength() == 0); TResponse res2 = DavResourceUtils.propfind("box/propfind-col-allprop.txt", readAclToken, HttpStatus.SC_MULTI_STATUS, testCol); // PROPFIND(XML?)?ACL????? // ACL?????? NodeList list2 = res2.bodyAsXml().getElementsByTagNameNS("DAV:", "acl"); assertTrue(res2.getBody(), list2.getLength() > 0); } finally { // ? DavResourceUtils.deleteCollection(Setup.TEST_CELL1, Setup.TEST_BOX1, testCol, AbstractCase.MASTER_TOKEN_NAME, -1); // ????? ResourceUtils.linkAccountRollDelete(Setup.TEST_CELL1, AbstractCase.MASTER_TOKEN_NAME, accountReadAcl, null, "roleReadAcl"); ResourceUtils.linkAccountRollDelete(Setup.TEST_CELL1, AbstractCase.MASTER_TOKEN_NAME, accountRead, null, "roleRead"); // Role? RoleUtils.delete(Setup.TEST_CELL1, AbstractCase.MASTER_TOKEN_NAME, null, "roleRead"); RoleUtils.delete(Setup.TEST_CELL1, AbstractCase.MASTER_TOKEN_NAME, null, "roleReadAcl"); // Account? AccountUtils.delete(Setup.TEST_CELL1, AbstractCase.MASTER_TOKEN_NAME, accountReadAcl, HttpStatus.SC_NO_CONTENT); AccountUtils.delete(Setup.TEST_CELL1, AbstractCase.MASTER_TOKEN_NAME, accountRead, HttpStatus.SC_NO_CONTENT); } } /** * ContentLength????PROPFIND?. */ @Test public final void ContentLength? ???PROPFIND?() { TResponse tresponse = Http.request("box/propfind-non-content-length.txt") .with("path", Setup.TEST_ODATA) .with("depth", "0") .with("token", TOKEN) .returns(); tresponse.statusCode(HttpStatus.SC_MULTI_STATUS); } /** * body?propfind?????PROPFIND?400???. */ @Test public final void body?propfind?????PROPFIND?400 ???() { // propfind // propfinds String body = "<?xml version=\"1.0\" encoding=\"utf-8\"?>" + "<D:propfinds xmlns:D=\"DAV:\"><D:allprop/></D:propfinds>"; TResponse tresponse = Http.request("box/propfind-body.txt").with("path", Setup.TEST_ODATA) .with("depth", "0").with("token", TOKEN).with("body", body).returns(); tresponse.statusCode(HttpStatus.SC_BAD_REQUEST); } /** * body?allprop?????PROPFIND?400???. TODO V1.1 PROPFIND??? */ @Test @Ignore public final void body?allprop?????PROPFIND?400 ???() { String body = "<?xml version=\"1.0\" encoding=\"utf-8\"?>" + "<D:propfind xmlns:D=\"DAV:\"><D:allprope/></D:propfind>"; TResponse tresponse = Http.request("box/propfind-body.txt").with("path", Setup.TEST_ODATA) .with("depth", "0").with("token", TOKEN).with("body", body).returns(); tresponse.statusCode(HttpStatus.SC_BAD_REQUEST); } /** * ????PUT?409???. */ @Test public final void ????PUT?409 ???() { String davFileName = "davFile.txt"; // ???WebDav??Dav?? // testcell1/box1/hogecol/davFile.txt DavResourceUtils.createWebDavFile(Setup.TEST_CELL1, TOKEN, "box/dav-put.txt", "hoge", Setup.TEST_BOX1, "hogecol" + "/" + davFileName, HttpStatus.SC_CONFLICT); } /** * ????MKCOL?409???. */ @Test public final void ????MKCOL?409 ???() { String colName = "colHoge/colhuga"; // ?????Odata?? // testcell1/box1/colHoge/colhuga DavResourceUtils.createODataCollection(TOKEN, HttpStatus.SC_CONFLICT, Setup.TEST_CELL1, Setup.TEST_BOX1, colName); } /** * ????PUT?409???. */ @Test public final void ????PUT?409 ???() { String davFileName = "davFile.txt"; // ???WebDav??Dav?? // testcell1/box1/hogecol/davFile.txt DavResourceUtils.createWebDavFile(Setup.TEST_CELL1, TOKEN, "box/dav-put.txt", "hoge", Setup.TEST_BOX1, "hogecol" + "/" + "hugacol/" + davFileName, HttpStatus.SC_CONFLICT); } /** * XML????????. * @param doc * @param tagName ?? * @return result ?? */ private String getXmlNodeValue(final Document doc, final String tagName) { return DavResourceUtils.getXmlNodeValue(doc, tagName); } /** * PROPPATCH????. * @param doc ??XML * @param resorce PROPPATCH?? * @param map ???KeyValue Key?Value???????? Valuenull???Key??????remove???? */ private void proppatchResponseTest(Element doc, String resorce, Map<String, String> map) { NodeList response = doc.getElementsByTagName("response"); assertEquals(1, response.getLength()); Element node = (Element) response.item(0); assertEquals(resorce, node.getElementsByTagName("href").item(0).getFirstChild().getNodeValue()); assertEquals("HTTP/1.1 200 OK", node.getElementsByTagName("status").item(0).getFirstChild().getNodeValue()); for (Iterator<String> it = map.keySet().iterator(); it.hasNext();) { Object key = it.next(); Object value = map.get(key); String textContext = null; NodeList tmp = node.getElementsByTagName("prop").item(0).getChildNodes(); for (int i = 0; i < tmp.getLength(); i++) { Node child = tmp.item(i); if (child instanceof Element) { Element childElement = (Element) child; if (childElement.getLocalName().equals(key)) { textContext = childElement.getTextContent(); break; } } } assertEquals(value, textContext); } } /** * PROPPATCH????. * @param doc ??XML * @param resorce PROPPATCH?? * @param lapName prop?????? * @param map ???KeyValue Key?Value???????? Valuenull???Key??????remove???? */ private void proppatchClassResponseTest(Element doc, String resorce, String lapName, ArrayList<String> list) { NodeList response = doc.getElementsByTagName("response"); assertEquals(1, response.getLength()); Element node = (Element) response.item(0); assertEquals(resorce, node.getElementsByTagName("href").item(0).getFirstChild().getNodeValue()); assertEquals("HTTP/1.1 200 OK", node.getElementsByTagName("status").item(0).getFirstChild().getNodeValue()); String lapNameFlg = null; NodeList tmp = node.getElementsByTagName("prop").item(0).getChildNodes(); for (int i = 0; i < tmp.getLength(); i++) { Node child = tmp.item(i); if (child instanceof Element) { // ????? Element childElement = (Element) child; if (childElement.getLocalName().equals(lapName)) { lapNameFlg = "true"; // Path?? NodeList pTmp = childElement.getChildNodes(); for (int ii = 0; ii < pTmp.getLength(); ii++) { Node pChild = pTmp.item(ii); if (pChild instanceof Element) { Element pChildElement = (Element) pChild; NamedNodeMap attrs = pChildElement.getAttributes(); if (attrs != null) { String falg = null; for (Iterator<String> it = list.listIterator(); it.hasNext();) { Object key = it.next(); Object value = it.next(); Node attr = (Node) attrs.getNamedItem((String) key); if (attr != null && attr.getNodeValue().equals(value)) { falg = "true"; } } assertNotNull(falg); } } } } } } // ????? assertNotNull(lapNameFlg); } /** * entityType?. * @param odataName * @param token * @param accept * @return */ private TResponse entityTypeDelete(final String odataName, final String token, final String accept, final String entSetName, final String cellPath, final int code) { TResponse tresponse = Http.request("box/entitySet-delete.txt").with("cellPath", cellPath) .with("boxPath", "box1").with("odataSvcPath", odataName).with("token", token).with("accept", accept) .with("Name", entSetName).returns().statusCode(code); return tresponse; } }