MARMOTTA-499: added test, both at the service and webservice level
Project: http://git-wip-us.apache.org/repos/asf/marmotta/repo Commit: http://git-wip-us.apache.org/repos/asf/marmotta/commit/99cca9dc Tree: http://git-wip-us.apache.org/repos/asf/marmotta/tree/99cca9dc Diff: http://git-wip-us.apache.org/repos/asf/marmotta/diff/99cca9dc Branch: refs/heads/develop Commit: 99cca9dc9e13bb41e6a45f16f9b260f52a237123 Parents: f89f61f Author: Sergio Fernández <[email protected]> Authored: Wed Jul 9 07:42:47 2014 +0200 Committer: Sergio Fernández <[email protected]> Committed: Wed Jul 9 07:42:47 2014 +0200 ---------------------------------------------------------------------- .../modules/MarmottaResourceServiceImpl.java | 8 +- .../modules/MarmottaResourceServiceTest.java | 79 ++++++++++++++++++++ 2 files changed, 82 insertions(+), 5 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/marmotta/blob/99cca9dc/platform/marmotta-core/src/main/java/org/apache/marmotta/platform/core/services/modules/MarmottaResourceServiceImpl.java ---------------------------------------------------------------------- diff --git a/platform/marmotta-core/src/main/java/org/apache/marmotta/platform/core/services/modules/MarmottaResourceServiceImpl.java b/platform/marmotta-core/src/main/java/org/apache/marmotta/platform/core/services/modules/MarmottaResourceServiceImpl.java index a1638bf..f735e39 100644 --- a/platform/marmotta-core/src/main/java/org/apache/marmotta/platform/core/services/modules/MarmottaResourceServiceImpl.java +++ b/platform/marmotta-core/src/main/java/org/apache/marmotta/platform/core/services/modules/MarmottaResourceServiceImpl.java @@ -163,7 +163,7 @@ public class MarmottaResourceServiceImpl implements MarmottaResourceService { } // the base URL of the jar file in the file system - String jarUrlBase = resourceMap.get(key); + String jarUrlBase = resourceMap.get(key); // the JAR URL of the resource inside the jar file String jarUrlEntry; @@ -176,10 +176,8 @@ public class MarmottaResourceServiceImpl implements MarmottaResourceService { try { return new URL(jarUrlEntry); - } catch(IOException ex) { - log.debug("error while trying to retrieve resource {}: {}",jarUrlEntry,ex.getMessage()); - + log.debug("error while trying to retrieve resource {}: {}", jarUrlEntry, ex.getMessage()); } } } @@ -206,7 +204,7 @@ public class MarmottaResourceServiceImpl implements MarmottaResourceService { */ private void putInCache(String key, ResourceEntry data) { if(isCacheEnabled()) { - resourceCache.put(key,data); + resourceCache.put(key, data); } } http://git-wip-us.apache.org/repos/asf/marmotta/blob/99cca9dc/platform/marmotta-core/src/test/java/org/apache/marmotta/platform/core/test/modules/MarmottaResourceServiceTest.java ---------------------------------------------------------------------- diff --git a/platform/marmotta-core/src/test/java/org/apache/marmotta/platform/core/test/modules/MarmottaResourceServiceTest.java b/platform/marmotta-core/src/test/java/org/apache/marmotta/platform/core/test/modules/MarmottaResourceServiceTest.java new file mode 100644 index 0000000..d4b6a24 --- /dev/null +++ b/platform/marmotta-core/src/test/java/org/apache/marmotta/platform/core/test/modules/MarmottaResourceServiceTest.java @@ -0,0 +1,79 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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 org.apache.marmotta.platform.core.test.modules; + +import com.jayway.restassured.RestAssured; +import org.apache.marmotta.platform.core.api.modules.MarmottaResourceService; +import org.apache.marmotta.platform.core.api.modules.ResourceEntry; +import org.apache.marmotta.platform.core.test.base.JettyMarmotta; +import org.apache.marmotta.platform.core.webservices.prefix.PrefixWebService; +import org.junit.AfterClass; +import org.junit.Assert; +import org.junit.BeforeClass; +import org.junit.Test; + +import java.io.IOException; + +import static com.jayway.restassured.RestAssured.expect; +import static com.jayway.restassured.RestAssured.given; +import static org.hamcrest.Matchers.equalTo; + +/** + * Marmotta Resources test + * + * @author Sergio Fernández + */ +public class MarmottaResourceServiceTest { + + private static JettyMarmotta marmotta; + private static MarmottaResourceService resourceService; + + @BeforeClass + public static void setUp() { + marmotta = new JettyMarmotta("/marmotta", PrefixWebService.class); + resourceService = marmotta.getService(MarmottaResourceService.class); + + RestAssured.baseURI = "http://localhost"; + RestAssured.port = marmotta.getPort(); + RestAssured.basePath = marmotta.getContext(); + } + + @AfterClass + public static void tearDown() { + marmotta.shutdown(); + } + + @Test + public void testMARMOTTA499() { + + final String resource = "/core/public/style/blue/style.css"; + final String expectedMimeType = "text/css"; + + ResourceEntry resourceEntry = resourceService.getResource(resource); + Assert.assertEquals(expectedMimeType, resourceEntry.getContentType()); + + given(). + expect(). + statusCode(200). + contentType(expectedMimeType). + when(). + get(resource); + + } + +}
