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.utils; import static org.fest.assertions.Assertions.assertThat; import static org.junit.Assert.assertEquals; import static org.junit.Assert.fail; import java.io.StringWriter; import java.util.List; import javax.xml.bind.JAXBContext; import javax.xml.bind.JAXBException; import javax.xml.bind.Marshaller; import org.apache.http.HttpStatus; import org.w3c.dom.Document; import org.w3c.dom.Element; import org.w3c.dom.Node; import org.w3c.dom.NodeList; import org.w3c.dom.Text; import com.fujitsu.dc.core.auth.OAuth2Helper; import com.fujitsu.dc.test.jersey.AbstractCase; import com.fujitsu.dc.test.jersey.box.acl.jaxb.Ace; import com.fujitsu.dc.test.jersey.box.acl.jaxb.Acl; import com.fujitsu.dc.test.jersey.box.acl.jaxb.Grant; import com.fujitsu.dc.test.jersey.box.acl.jaxb.Principal; import com.fujitsu.dc.test.jersey.box.acl.jaxb.Privilege; import com.fujitsu.dc.test.setup.Setup; import com.fujitsu.dc.test.unit.core.UrlUtils; /** * WebDAV Http?. */ public class DavResourceUtils { private static final String ACL_AUTH_TEST_SETTING_FILE = "box/acl-authtest.txt"; private DavResourceUtils() { } /** * ???ACL(deleteACL?). * @param path ?? * @param cellName ?? */ public static void createWebDavCollection(String path, String cellName) { // ? createWebDavCollection(AbstractCase.MASTER_TOKEN_NAME, HttpStatus.SC_CREATED, path); // ACL setACL(cellName, AbstractCase.MASTER_TOKEN_NAME, HttpStatus.SC_OK, path, ACL_AUTH_TEST_SETTING_FILE, Setup.TEST_BOX1, OAuth2Helper.SchemaLevel.NONE); } /** * MKCOL?????. * @param token (???) * @param code ?? * @param cell ?? * @param box ?? * @param path ??? * @return ? */ public static TResponse createWebDavCollectionWithAnyAuthSchema(String token, int code, String cell, String box, String path) { TResponse res = Http.request("box/mkcol-normal-anyAuthSchema.txt").with("cellPath", "testcell1") .with("cellPath", cell).with("box", box).with("path", path).with("token", token).returns(); res.statusCode(code); return res; } /** * MKCOL?????. * @param token Bearer * @param code ?? * @param cell ?? * @param box ?? * @param path ??? * @return ? */ public static TResponse createWebDavCollection(String token, int code, String cell, String box, String path) { TResponse res = Http.request("box/mkcol-normal-anyAuthSchema.txt").with("cellPath", "testcell1") .with("cellPath", cell).with("box", box).with("path", path).with("token", "Bearer " + token) .returns(); res.statusCode(code); return res; } /** * MKCOL?????(testcell1, box1). * @param token * @param code ?? * @param path ???(/testcell1/box1/ ??) * @return ? */ @Deprecated public static TResponse createWebDavCollection(String token, int code, String path) { TResponse res = Http.request("box/mkcol-normal.txt").with("cellPath", "testcell1").with("path", path) .with("token", token).returns(); res.statusCode(code); return res; } /** * ??. * @param fileName ?? * @param cellName * @param path * @param token * @param code * @return ? */ @Deprecated public static TResponse createWebDavCollection(String fileName, String cellName, String path, String token, int code) { TResponse res = Http.request(fileName).with("cellPath", cellName).with("path", path).with("token", token) .returns().statusCode(code); return res; } /** * MKCOL??????????. * @param token * @param code ?? * @param path ?? * @param cellName ?? */ public static void createWebDavCollectionWithDelete(String token, int code, String path, String cellName) { TResponse res = createWebDavCollection(token, code, path); if (res.getStatusCode() == HttpStatus.SC_CREATED) { // ? ResourceUtils.delete("box/delete-col.txt", cellName, AbstractCase.MASTER_TOKEN_NAME, HttpStatus.SC_NO_CONTENT, path); } } /** * MKCOL?????. * @param token * @param code ?? * @param path ??? * @return ? */ public static TResponse createServiceCollection(String token, int code, String path) { TResponse res = Http.request("box/mkcol-service.txt").with("cellPath", "testcell1").with("path", path) .with("token", token).returns(); res.statusCode(code); return res; } /** * MKCOL?????. * @param token * @param code ?? * @param cell ???? * @param box ???? * @param col ???? * @return ? */ public static TResponse createServiceCollection(String token, int code, String cell, String box, String col) { TResponse res = Http.request("box/mkcol-service-fullpath.txt").with("cell", cell).with("box", box) .with("col", col).with("token", token).returns().debug(); res.statusCode(code); return res; } /** * ?????. * @param token * @param code ?? * @param cell ?? * @param box ?? * @param path ? * @param svcFileName ?? * @param svcName ?? * @return ? */ public static TResponse setServiceProppatch(String token, int code, String cell, String box, String path, String svcFileName, String svcName) { return Http.request("box/proppatch-set-service-path.txt").with("cell", cell).with("box", box) .with("path", path).with("token", token).with("name", svcName).with("src", svcFileName).returns() .statusCode(code); } /** * MKCOL?????. * @param token * @param code ?? * @param cellPath ? * @param boxPath ? * @param colPath ??? * @return ? */ public static TResponse createODataCollection(String token, int code, String cellPath, String boxPath, String colPath) { TResponse res = Http.request("box/mkcol-odata.txt").with("cellPath", cellPath).with("boxPath", boxPath) .with("path", colPath).with("token", token).returns(); res.statusCode(code); return res; } /** * ?. * @param cellName ?? * @param box ?? * @param path * @param token * @param code * @return ? */ public static TResponse deleteCollection(String cellName, String box, String path, String token, int code) { TResponse res = Http.request("box/delete-box-col.txt").with("cellPath", cellName).with("box", box) .with("path", path).with("token", token).returns().statusCode(code); return res; } /** * ?. * @param cellName ?? * @param box ?? * @param path * @param token (???) * @param code * @return ? */ public static TResponse deleteCollectionWithAnyAuthSchema(String cellName, String box, String path, String token, int code) { TResponse res = Http.request("box/delete-box-col-anyAuthSchema.txt").with("cellPath", cellName) .with("box", box).with("path", path).with("token", token).returns().statusCode(code); return res; } /** * ?PROPPATCH?. * @param url URL * @param token ? * @param file * @param code ? * @return ? */ public static TResponse setProppatch(String url, String token, String file, int code) { // PROPPATCH TResponse tresponse = Http.request(file).with("path", url).with("token", token).returns(); tresponse.statusCode(code); return tresponse; } /** * PROPPATCH?. * @param url URL * @param token ? * @param code ? * @param values * @return ? */ public static TResponse setProppatch(String url, String token, int code, String... values) { // PROPPATCH TResponse tresponse = Http.request("cell/proppatch-set.txt").with("path", url).with("token", token) .with("author1", values[0]).with("hoge", values[1]).returns(); tresponse.statusCode(code); return tresponse; } /** * PROPPATCH?????. * @param token * @param code ?? * @param cell ?? * @param box ?? * @param path ? * @return ? */ public static TResponse setProppatch(String token, int code, String cell, String box, String path) { return Http.request("box/proppatch-set.txt").with("cell", cell).with("box", box).with("path", path) .with("token", token).with("author1", "Test User1").with("hoge", "hoge").returns().debug() .statusCode(code); } /** * PROPPATCH?????. * @param token * @param code ?? * @param path ? */ public static void setProppatch(String token, int code, String path) { setProppatch(token, code, "testcell1", "box1", path); } /** * PROPPATCH?. * @param url URL * @param token ? * @param code ? * @param propKey prop? * @param values * @return ? */ public static TResponse setProppatchSetPropKey(String url, String token, int code, String propKey, String... values) { // PROPPATCH // TResponse tresponse = Http.request("cell/proppatch-set.txt") TResponse tresponse = Http.request("cell/proppatch-set-setPropKey.txt").with("path", url) .with("token", token).with("propkey", propKey).with("author1", values[0]).with("hoge", values[1]) .returns(); tresponse.statusCode(code); return tresponse; } /** * PROPPATCH??. * @param url URL * @param token ? * @return ? */ public static TResponse resetProppatch(String url, String token) { // ? TResponse tresponse = Http.request("cell/proppatch-remove.txt").with("path", url).with("token", token) .returns(); tresponse.statusCode(HttpStatus.SC_MULTI_STATUS); return tresponse; } /** * PROPPATCH??. * @param url URL * @param token ? * @param code ? * @param propKey prop? * @return ? */ public static TResponse resetProppatchSetPropKey(String url, String token, int code, String propKey) { // ? TResponse tresponse = Http.request("cell/proppatch-remove-setPropKey.txt").with("path", url) .with("token", token).with("propkey", propKey).returns(); tresponse.statusCode(code); return tresponse; } /** * ACL. * @param cell ?? * @param token * @param code ?? * @param path ?? * @param settingFile ACL * @param role ACL??PrincipalRole * @param privilege ACL??? * @param level ?level * @return ? */ public static TResponse setACL(String cell, String token, int code, String path, String settingFile, String role, String privilege, String level) { TResponse tresponseWebDav = null; // ACL? tresponseWebDav = Http.request(settingFile).with("cellPath", cell).with("colname", path) .with("token", token).with("role", role).with("privilege", privilege) .with("roleBaseUrl", UrlUtils.roleResource(cell, null, "")).with("level", level).returns() .statusCode(code); return tresponseWebDav; } /** * ACL. * @param cell ?? * @param token * @param code ?? * @param path ??(cell?) * @param requireSchemaAuthz ?level * @return ? */ public static TResponse setACLPrivilegeAllForAllUser(String cell, String token, int code, String path, String requireSchemaAuthz) { TResponse tresponseWebDav = null; // ACL? tresponseWebDav = Http.request("box/acl-setting-all.txt").with("colname", path).with("token", token) .with("privilege", "<D:all/>").with("roleBaseUrl", UrlUtils.roleResource(cell, null, "")) .with("level", requireSchemaAuthz).returns().statusCode(code); return tresponseWebDav; } /** * ACL. * @param cell ?? * @param token * @param code ?? * @param path ??(cell?) * @param privilege ??? * @param requireSchemaAuthz ?level * @return ? */ public static TResponse setACLPrincipalAll(String cell, String token, int code, String path, String privilege, String requireSchemaAuthz) { TResponse tresponseWebDav = null; // ACL? tresponseWebDav = Http.request("box/acl-setting-all.txt").with("colname", path).with("token", token) .with("privilege", privilege).with("roleBaseUrl", UrlUtils.roleResource(cell, null, "")) .with("level", requireSchemaAuthz).returns().statusCode(code); return tresponseWebDav; } /** * ACL. * @param cell ?? * @param token * @param code ?? * @param path ?? * @param settingFile ACL * @param boxName box?? * @param level ?level * @return ? */ public static TResponse setACL(String cell, String token, int code, String path, String settingFile, String boxName, String level) { TResponse tresponseWebDav = null; // ACL? tresponseWebDav = Http.request(settingFile).with("cellPath", cell).with("colname", path) .with("roleBaseUrl", UrlUtils.roleResource(cell, null, "")).with("box", boxName) .with("token", token).with("level", level).returns().statusCode(code); return tresponseWebDav; } /** * ACL. * @param cell ?? * @param token * @param code ?? * @param box ? * @param colname ?? * @param settingFile ACL * @param roleBaseUrl ACL??PrincipalRole * @param privilege ACL??? * @param level ?level * @return ? */ @Deprecated public static TResponse setACLwithRoleBaseUrl(String cell, String token, int code, String box, String colname, String settingFile, String roleBaseUrl, String privilege, String level) { TResponse tresponseWebDav = null; // ACL? tresponseWebDav = Http.request(settingFile).with("cellPath", cell).with("box", box).with("colname", colname) .with("token", token).with("privilege", privilege).with("roleBaseUrl", roleBaseUrl) .with("level", level).returns().statusCode(code); return tresponseWebDav; } /** * ACL. * @param token * @param cell ?? * @param code ?? * @param box ? * @param colname ?? * @param requireSchemaAuthz ?level * @param roleBaseUrl ACL??PrincipalRole * @param privilege ACL??? * @return ? */ public static TResponse setACLwithRoleBaseUrl(String token, String cell, String box, String colname, String requireSchemaAuthz, String roleBaseUrl, String privilege, int code) { return Http.request("box/acl-setting-baseurl.txt").with("cellPath", cell).with("box", box) .with("colname", colname).with("token", token).with("level", requireSchemaAuthz) .with("privilege", privilege).with("roleBaseUrl", roleBaseUrl).returns().debug().statusCode(code); } /** * ACL. * @param cell ?? * @param token * @param code ?? * @param box ? * @param colname ?? * @param role ?? * @param settingFile ACL * @param roleBaseUrl ACL??PrincipalRole * @param privilege ACL??? * @param level ?level * @return ? */ public static TResponse setACLwithRoleBaseUrl(String cell, String token, int code, String box, String colname, String role, String settingFile, String roleBaseUrl, String privilege, String level) { TResponse tresponseWebDav = null; // ACL? tresponseWebDav = Http.request(settingFile).with("cellPath", cell).with("box", box).with("colname", colname) .with("role", role).with("token", token).with("privilege", privilege) .with("roleBaseUrl", roleBaseUrl).with("level", level).returns().statusCode(code); return tresponseWebDav; } /** * ACL. * @param cell ?? * @param token * @param code ?? * @param box ? * @param path ?? * @param settingFile ACL * @param role1 ACL??PrincipalRole * @param role2 ACL??PrincipalRole * @param roleLinkToBox ?????? * @param privilege1 ACL??? * @param privilege2 ACL??? * @param level ?level * @return ? */ public static TResponse setACLwithBox(String cell, String token, int code, String box, String path, String settingFile, String role1, String role2, String roleLinkToBox, String privilege1, String privilege2, String level) { TResponse tresponseWebDav = null; // ACL? tresponseWebDav = Http.request(settingFile).with("cellPath", cell).with("box", box).with("colname", path) .with("token", token).with("role1", role1).with("role2", role2).with("privilege1", privilege1) .with("privilege2", privilege2).with("roleBaseUrl", UrlUtils.roleResource(cell, roleLinkToBox, "")) .with("level", level).returns().statusCode(code); return tresponseWebDav; } /** * ACL. * @param cell ?? * @param token * @param code ?? * @param box ? * @param path ?? * @param settingFile ACL * @param role ACL??PrincipalRole * @param roleLinkToBox ?????? * @param privilege ACL??? * @param level ?level * @return ? */ public static TResponse setACLwithBox(String cell, String token, int code, String box, String path, String settingFile, String role, String roleLinkToBox, String privilege, String level) { TResponse tresponseWebDav = null; // ACL? tresponseWebDav = Http.request(settingFile).with("cellPath", cell).with("box", box).with("colname", path) .with("token", token).with("role", role).with("privilege", privilege) .with("roleBaseUrl", UrlUtils.roleResource(cell, roleLinkToBox, "")).with("level", level).returns() .statusCode(code); return tresponseWebDav; } /** * BoxACL?. * <p> * * <pre> * Acl acl = new Acl(); * acl.getAce().add(DavResourceUtils.createAce(false, roleRead, "read")); * acl.getAce().add(DavResourceUtils.createAce(false, roleWrite, "write")); * acl.setXmlbase(String.format("%s/%s/__role/%s/", * UrlUtils.getBaseUrl(), CELL_NAME, Box.DEFAULT_BOX_NAME)); * DavResourceUtils.setAcl(MASTER_TOKEN, CELL_NAME, BOX_NAME, COL_NAME, acl, HttpStatus.SC_OK); * </pre> * </p> * @param token * @param cell ?? * @param box ?? * @param col ?? * @param acl ?ACL * @param code ? * @return ? * @throws JAXBException ACL???????? */ public static TResponse setAcl(String token, String cell, String box, String col, Acl acl, int code) throws JAXBException { StringWriter writer = new StringWriter(); JAXBContext context = JAXBContext.newInstance(Acl.class); Marshaller marshaller = context.createMarshaller(); marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); marshaller.marshal(acl, writer); return Http.request("box/acl-setting-none-body.txt").with("cell", cell).with("box", box) .with("colname", col).with("token", token).with("body", writer.toString()).returns().debug() .statusCode(code); } /** * BoxACL??ACE?. * @param isPrincipalAll ??? all ?????? * @param role ??? all ????????URL or URI) * @param privilege ?? * @return ???Ace */ public static Ace createAce(boolean isPrincipalAll, String role, String privilege) { Principal principal = new Principal(); if (isPrincipalAll) { principal.setAll(""); } else { principal.setHref(role); } Grant grant = new Grant(); grant.getPrivilege().add(createPrivilege(privilege)); Ace ace = new Ace(); ace.setPrincipal(principal); ace.setGrant(grant); return ace; } /** * BoxACL??ACE?. * @param isPrincipalAll ??? all ?????? * @param role ??? all ????????URL or URI) * @param privileges ?? * @return ???Ace */ public static Ace createAce(boolean isPrincipalAll, String role, List<String> privileges) { Principal principal = new Principal(); principal.setHref(role); Grant grant = new Grant(); for (String privilege : privileges) { grant.getPrivilege().add(createPrivilege(privilege)); } Ace ace = new Ace(); ace.setPrincipal(principal); ace.setGrant(grant); return ace; } /** * BoxACL????. * @param type ?? * @return ???Privilege */ public static Privilege createPrivilege(String type) { Privilege privilege = new Privilege(); if ("read".equals(type)) { privilege.setRead(""); } else if ("write".equals(type)) { privilege.setWrite(""); } else if ("alter-schema".equals(type)) { privilege.setAlterSchema(""); } else if ("read-properties".equals(type)) { privilege.setReadProperties(""); } else if ("write-properties".equals(type)) { privilege.setWriteProperties(""); } else if ("read-acl".equals(type)) { privilege.setReadAcl(""); } else if ("write-acl".equals(type)) { privilege.setWriteAcl(""); } else if ("bind".equals(type)) { privilege.setBind(""); } else if ("unbind".equals(type)) { privilege.setUnbind(""); } else if ("exec".equals(type)) { privilege.setExec(""); } else if ("all".equals(type)) { privilege.setAll(""); } return privilege; } /** * PROPFIND?????. * @param token * @param cell Cell?? * @param path Box?? * @param depth Depth? * @param code ?? * @return ? */ public static TResponse propfind(String token, String cell, String path, String depth, int code) { TResponse res = Http.request("box/propfind-box-allprop.txt").with("cellPath", cell).with("path", path) .with("depth", depth).with("token", token).returns().statusCode(code); return res; } /** * PROPFIND?????. * @param fileName ?? * @param token * @param code ?? * @param path ?? * @return ? */ @Deprecated public static TResponse propfind(String fileName, String token, int code, String path) { TResponse res = Http.request(fileName).with("cellPath", Setup.TEST_CELL1).with("path", path) .with("depth", "0").with("token", token).returns().statusCode(code); return res; } /** * PROPFIND?????. * @param reqFile ?? * @param token * @param cellName ?? * @param path ?? * @param depth ? ( 0 or 1 ) * @param code ?? * @return ? */ @Deprecated public static TResponse propfind(String reqFile, String token, String cellName, String path, int depth, int code) { TResponse res = Http.request(reqFile).with("token", token).with("cellPath", cellName).with("path", path) .with("depth", String.valueOf(depth)).returns().statusCode(code); return res; } /** * WebDAV??. * @param cell ?? * @param token * @param boxName box?? * @param path Box * @param code ? * @return ? */ public static TResponse getWebDav(String cell, String token, String boxName, String path, int code) { return Http.request("box/dav-get.txt").with("cellPath", cell).with("token", token).with("box", boxName) .with("path", path).returns().debug().statusCode(code); } /** * File??. * @param cell ?? * @param token * @param fileName ?? * @param boxName box?? * @param path Box * @param code ? * @return ? */ @Deprecated public static TResponse getWebDavFile(String cell, String token, String fileName, String boxName, String path, int code) { TResponse res = Http.request(fileName).with("cellPath", cell).with("token", token).with("box", boxName) .with("path", path).returns().statusCode(code); return res; } /** * File??. * @param cell ?? * @param token * @param fileName ?? * @param fileBody * @param boxName box?? * @param path Box * @param code * @return */ @Deprecated public static TResponse createWebDavFile(String cell, String token, String fileName, String fileBody, String boxName, String path, int code) { TResponse res = Http.request(fileName).with("cellPath", cell).with("token", token).with("box", boxName) .with("path", path).with("contentType", javax.ws.rs.core.MediaType.TEXT_PLAIN) .with("source", fileBody).returns().statusCode(code); return res; } /** * File??. * @param token * @param cell ?? * @param path Box? * @param fileBody * @param contentType ?Mime * @param code * @return ? */ public static TResponse createWebDavFile(String token, String cell, String path, String fileBody, String contentType, int code) { return Http.request("box/dav-put-with-body.txt").with("cellPath", cell).with("token", token) .with("path", path).with("contentType", contentType).with("source", fileBody).returns().debug() .statusCode(code); } /** * File??(??). * @param cell ?? * @param fileName ?? * @param fileBody * @param boxName box?? * @param path Box * @param code * @return */ public static TResponse createWebDavFileNoAuthHeader(String cell, String fileName, String fileBody, String boxName, String path, int code) { TResponse res = Http.request(fileName).with("cellPath", cell).with("box", boxName).with("path", path) .with("contentType", javax.ws.rs.core.MediaType.TEXT_PLAIN).with("source", fileBody).returns() .statusCode(code); return res; } /** * WebDAV?. * @param token * @param cell ?? * @param path Box? * @param destination ?URL? * @param code * @return ? */ public static TResponse moveWebDav(String token, String cell, String path, String destination, int code) { return Http.request("box/dav-move.txt").with("cellPath", cell).with("authorization", "Bearer " + token) .with("path", path).with("destination", destination).returns().debug().statusCode(code); } /** * WebDAV?. * @param token * @param cell ?? * @param path Box? * @param destination ?URL? * @param ifMatch IfMatch * @param overWrite ?? * @param depth depth * @param code * @return ? */ public static TResponse moveWebDav(String token, String cell, String path, String destination, String ifMatch, String overWrite, String depth, int code) { return Http.request("box/dav-move-with-header.txt").with("cellPath", cell) .with("authorization", "Bearer " + token).with("path", path).with("destination", destination) .with("ifMatch", ifMatch).with("overWrite", overWrite).with("depth", depth).returns().debug() .statusCode(code); } /** * WebDAV?. * @param authorization Authorization? * @param cell ?? * @param path Box? * @param destination ?URL? * @param code * @return ? */ public static TResponse moveWebDavWithAnyAuthSchema(String authorization, String cell, String path, String destination, int code) { return Http.request("box/dav-move.txt").with("cellPath", cell).with("authorization", authorization) .with("path", path).with("destination", destination).returns().debug().statusCode(code); } /** * File?. * @param fileName ?? * @param cell ?? * @param token * @param path * @param code ? * @param boxName box?? * @return ? */ @Deprecated public static TResponse deleteWebDavFile(String fileName, String cell, String token, String path, int code, String boxName) { TResponse res = Http.request(fileName).with("cellPath", cell).with("token", token).with("box", boxName) .with("path", path).returns().statusCode(code); return res; } /** * File?. * @param cell Cell?? * @param token * @param boxName Box?? * @param path * @return ? */ public static TResponse deleteWebDavFile(String cell, String token, String boxName, String path) { return Http.request("box/dav-delete-ifmatch.txt").with("cellPath", cell).with("etag", "*") .with("token", token).with("box", boxName).with("path", path).returns(); } /** * XML????????. * @param doc * @param tagName ?? * @return result ?? */ public static String getXmlNodeValue(final Document doc, final String tagName) { String result = null; Element root = doc.getDocumentElement(); // root???? assertEquals("multistatus", root.getTagName()); NodeList nl1 = root.getElementsByTagName(tagName); if (nl1 == null) { return null; } for (int i = 0; i < nl1.getLength(); i++) { result = (nl1.item(i)).getFirstChild().getNodeValue(); } return result; } /** * PROPFIND???OData?????????. <br /> * dc:odata?????? OData ??????. * @param res PROPFIND? */ public static void assertIsODataCol(TResponse res) { Document propfind = res.bodyAsXml(); NodeList list; list = propfind.getElementsByTagName("dc:odata"); assertThat(list.getLength()).isGreaterThanOrEqualTo(1); } /** * PROPFIND???Service?????????. <br /> * dc:path?????? Service ??????. * @param res PROPFIND? */ public static void assertIsServiceCol(TResponse res) { Document propfind = res.bodyAsXml(); NodeList list; list = propfind.getElementsByTagName("dc:path"); assertThat(list.getLength()).isGreaterThanOrEqualTo(1); } /** * PROPFIND???href ???URL?????????. * @param expectedUrl ?URL * @param res PROPFIND? */ public static void assertContainsHrefUrl(final String expectedUrl, TResponse res) { boolean isMatch = containsUrl(expectedUrl, res); assertEquals(true, isMatch); } /** * PROPFIND???href ???URL???????????. * @param expectedUrl ?URL * @param res PROPFIND? */ public static void assertNotContainsHrefUrl(final String expectedUrl, TResponse res) { boolean isMatch = containsUrl(expectedUrl, res); assertEquals(false, isMatch); } private static boolean containsUrl(final String expectedUrl, TResponse res) { Document propfind = res.bodyAsXml(); NodeList list; list = propfind.getElementsByTagName("href"); int index = 0; boolean isMatch = false; for (index = 0; index < list.getLength(); index++) { org.w3c.dom.Node node = list.item(index); NodeList children = node.getChildNodes(); assertEquals(1, children.getLength()); Text item = (Text) children.item(0); if (expectedUrl.equals(item.getNodeValue())) { isMatch = true; } } return isMatch; } /** * XML????????????????. * @param res PROPFIND? * @param tagName ????? * @param expectedNode ? */ public static void assertEqualsNodeInResXml(TResponse res, String tagName, Node expectedNode) { Document propfind = res.bodyAsXml(); NodeList list; list = propfind.getElementsByTagName(tagName); for (int i = 0; i < list.getLength(); i++) { Node item = list.item(i); if (item.isEqualNode(expectedNode)) { return; } } // ??????????? fail(); } /** * XML??????????????. * @param res PROPFIND? * @param tagName ????? */ public static void assertContainsNodeInResXml(TResponse res, String tagName) { Document propfind = res.bodyAsXml(); NodeList list; list = propfind.getElementsByTagName(tagName); assertThat(list.getLength()).isGreaterThan(0); } /** * XML????????????????. * @param res PROPFIND? * @param tagName ????? */ public static void assertNotContainsNodeInResXml(TResponse res, String tagName) { Document propfind = res.bodyAsXml(); NodeList list; list = propfind.getElementsByTagName(tagName); assertThat(list.getLength()).isEqualTo(0); } }