|
| 1 | +/* |
| 2 | + * eXist-db Open Source Native XML Database |
| 3 | + * Copyright (C) 2001 The eXist-db Authors |
| 4 | + * |
| 5 | + |
| 6 | + * http://www.exist-db.org |
| 7 | + * |
| 8 | + * This library is free software; you can redistribute it and/or |
| 9 | + * modify it under the terms of the GNU Lesser General Public |
| 10 | + * License as published by the Free Software Foundation; either |
| 11 | + * version 2.1 of the License, or (at your option) any later version. |
| 12 | + * |
| 13 | + * This library is distributed in the hope that it will be useful, |
| 14 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 16 | + * Lesser General Public License for more details. |
| 17 | + * |
| 18 | + * You should have received a copy of the GNU Lesser General Public |
| 19 | + * License along with this library; if not, write to the Free Software |
| 20 | + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
| 21 | + */ |
| 22 | +package org.exist.xmlrpc; |
| 23 | + |
| 24 | +import static org.junit.Assert.assertEquals; |
| 25 | +import static org.junit.Assert.assertNotNull; |
| 26 | + |
| 27 | +import org.exist.TestUtils; |
| 28 | +import org.exist.test.ExistWebServer; |
| 29 | +import org.junit.AfterClass; |
| 30 | +import org.junit.BeforeClass; |
| 31 | +import org.junit.ClassRule; |
| 32 | +import org.junit.Test; |
| 33 | +import org.xml.sax.SAXException; |
| 34 | +import org.xmldb.api.DatabaseManager; |
| 35 | +import org.xmldb.api.base.Collection; |
| 36 | +import org.xmldb.api.base.Database; |
| 37 | +import org.xmldb.api.base.Resource; |
| 38 | +import org.xmldb.api.base.XMLDBException; |
| 39 | +import org.xmldb.api.modules.CollectionManagementService; |
| 40 | +import org.xmldb.api.modules.XMLResource; |
| 41 | + |
| 42 | +public class MimeTypeTest { |
| 43 | + |
| 44 | + @ClassRule |
| 45 | + public final static ExistWebServer existWebServer = new ExistWebServer(true, false, true, true); |
| 46 | + |
| 47 | + private final static String COLLECTION_NAME = "rpctest"; |
| 48 | + private static final String DOCUMENT_NAME = "myxmldoc"; |
| 49 | + private final static String XML_CONTENT = "<xml><it><is></is></it></xml>"; |
| 50 | + |
| 51 | + private static String getBaseUri() { |
| 52 | + return "xmldb:exist://localhost:" + existWebServer.getPort() + "/xmlrpc"; |
| 53 | + } |
| 54 | + |
| 55 | + @Test |
| 56 | + public void testXMLMimeType() throws XMLDBException { |
| 57 | + // store an XML document without an .xml extension |
| 58 | + try(Collection collection = DatabaseManager.getCollection(getBaseUri() + "/db/" + COLLECTION_NAME, TestUtils.ADMIN_DB_USER, TestUtils.ADMIN_DB_PWD)){ |
| 59 | + final XMLResource resource = (XMLResource)collection.createResource(DOCUMENT_NAME, XMLResource.RESOURCE_TYPE); |
| 60 | + resource.setContent(XML_CONTENT); |
| 61 | + collection.storeResource(resource); |
| 62 | + assertEquals(XMLResource.RESOURCE_TYPE, resource.getResourceType()); |
| 63 | + } |
| 64 | + |
| 65 | + // retrieve the document and verify its resource type |
| 66 | + try(Collection collection = DatabaseManager.getCollection(getBaseUri() + "/db/" + COLLECTION_NAME, TestUtils.ADMIN_DB_USER, TestUtils.ADMIN_DB_PWD)){ |
| 67 | + Resource resource = collection.getResource(DOCUMENT_NAME); |
| 68 | + assertEquals(XMLResource.RESOURCE_TYPE, resource.getResourceType()); |
| 69 | + } |
| 70 | + } |
| 71 | + |
| 72 | + @BeforeClass |
| 73 | + public static void startServer() throws ClassNotFoundException, IllegalAccessException, InstantiationException, XMLDBException, SAXException { |
| 74 | + // initialize XML:DB driver |
| 75 | + Class<?> cl = Class.forName("org.exist.xmldb.DatabaseImpl"); |
| 76 | + Database database = (Database) cl.newInstance(); |
| 77 | + DatabaseManager.registerDatabase(database); |
| 78 | + |
| 79 | + Collection root = DatabaseManager.getCollection(getBaseUri() + "/db", TestUtils.ADMIN_DB_USER, TestUtils.ADMIN_DB_PWD); |
| 80 | + |
| 81 | + CollectionManagementService mgmt = (CollectionManagementService) root.getService("CollectionManagementService", "1.0"); |
| 82 | + assertNotNull(mgmt.createCollection(COLLECTION_NAME)); |
| 83 | + } |
| 84 | + |
| 85 | + @AfterClass |
| 86 | + public static void stopServer() throws XMLDBException { |
| 87 | + Collection root = DatabaseManager.getCollection(getBaseUri() + "/db", TestUtils.ADMIN_DB_USER, TestUtils.ADMIN_DB_PWD); |
| 88 | + CollectionManagementService mgmt = (CollectionManagementService) root.getService("CollectionManagementService", "1.0"); |
| 89 | + mgmt.removeCollection(COLLECTION_NAME); |
| 90 | + |
| 91 | + Collection config = DatabaseManager.getCollection(getBaseUri() + "/db/system/config/db", "admin", ""); |
| 92 | + mgmt = (CollectionManagementService) config.getService("CollectionManagementService", "1.0"); |
| 93 | + mgmt.removeCollection(COLLECTION_NAME); |
| 94 | + } |
| 95 | +} |
0 commit comments