This is an automated email from the ASF dual-hosted git repository.
enorman pushed a commit to branch master
in repository
https://gitbox.apache.org/repos/asf/sling-org-apache-sling-commons-contentdetection.git
The following commit(s) were added to refs/heads/master by this push:
new 49d042b SLING-12902 Update to Parent 62 (#4)
49d042b is described below
commit 49d042b815d9db1f65f11aee0dd5798f56a40d2a
Author: Eric Norman <[email protected]>
AuthorDate: Fri Aug 22 16:10:33 2025 -0700
SLING-12902 Update to Parent 62 (#4)
---
.sling-module.json | 8 +++
pom.xml | 56 ++++++++---------
.../ContentAwareMimeTypeService.java | 33 +++++-----
.../contentdetection/FileNameExtractor.java | 26 ++++----
.../internal/ContentAwareMimeTypeServiceImpl.java | 52 ++++++++--------
.../internal/FileNameExtractorImpl.java | 37 +++++------
.../ContentAwareMimeTypeServiceImplTest.java | 40 ++++++------
.../internal/FileNameExtractorImplTest.java | 43 +++++++------
.../it/ContentAwareMimeTypeServiceImplIT.java | 71 +++++++++++-----------
.../internal/it/ContentdetectionTestSupport.java | 44 +++++++-------
.../internal/it/FileNameExtractorImplIT.java | 36 +++++------
11 files changed, 230 insertions(+), 216 deletions(-)
diff --git a/.sling-module.json b/.sling-module.json
new file mode 100644
index 0000000..d4268ec
--- /dev/null
+++ b/.sling-module.json
@@ -0,0 +1,8 @@
+{
+ "jenkins": {
+ "jdks": [
+ 17,
+ 21
+ ]
+ }
+}
\ No newline at end of file
diff --git a/pom.xml b/pom.xml
index 3526e61..c2b7ff8 100644
--- a/pom.xml
+++ b/pom.xml
@@ -16,7 +16,6 @@
See the License for the specific language governing permissions and
limitations under the License.
-->
-
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
@@ -24,7 +23,7 @@
<parent>
<groupId>org.apache.sling</groupId>
<artifactId>sling-bundle-parent</artifactId>
- <version>38</version>
+ <version>62</version>
<relativePath />
</parent>
@@ -34,18 +33,19 @@
<name>Apache Sling Commons Content Detection</name>
<description>Content-based MIME type detection</description>
+ <scm>
+
<connection>scm:git:https://gitbox.apache.org/repos/asf/sling-org-apache-sling-commons-contentdetection.git</connection>
+
<developerConnection>scm:git:https://gitbox.apache.org/repos/asf/sling-org-apache-sling-commons-contentdetection.git</developerConnection>
+ <tag>HEAD</tag>
+
<url>https://gitbox.apache.org/repos/asf/sling-org-apache-sling-commons-contentdetection/tree/${project.scm.tag}</url>
+ </scm>
+
<properties>
+ <sling.java.version>17</sling.java.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
- <org.ops4j.pax.exam.version>4.13.3</org.ops4j.pax.exam.version>
+ <org.ops4j.pax.exam.version>4.14.0</org.ops4j.pax.exam.version>
</properties>
-
- <scm>
-
<connection>scm:git:https://gitbox.apache.org/repos/asf/sling-org-apache-sling-commons-contentdetection.git</connection>
-
<developerConnection>scm:git:https://gitbox.apache.org/repos/asf/sling-org-apache-sling-commons-contentdetection.git</developerConnection>
-
<url>http://sling.apache.org/documentation/bundles/mime-type-support-commons-mime.html</url>
- <tag>HEAD</tag>
- </scm>
<dependencies>
<!-- javax -->
@@ -55,6 +55,11 @@
<scope>test</scope>
</dependency>
<!-- OSGi -->
+ <dependency>
+ <groupId>org.osgi</groupId>
+ <artifactId>org.osgi.framework</artifactId>
+ <scope>provided</scope>
+ </dependency>
<dependency>
<groupId>org.osgi</groupId>
<artifactId>org.osgi.annotation.versioning</artifactId>
@@ -70,15 +75,10 @@
<artifactId>org.osgi.service.component.annotations</artifactId>
<scope>provided</scope>
</dependency>
- <dependency>
- <groupId>org.osgi</groupId>
- <artifactId>osgi.core</artifactId>
- <scope>provided</scope>
- </dependency>
<dependency>
<groupId>biz.aQute.bnd</groupId>
<artifactId>biz.aQute.bndlib</artifactId>
- <version>3.5.0</version>
+ <version>${bnd.version}</version>
<scope>test</scope>
</dependency>
<!-- Apache Commons -->
@@ -90,29 +90,29 @@
</dependency>
<!-- Apache Sling -->
<dependency>
- <version>2.1.8</version>
<groupId>org.apache.sling</groupId>
<artifactId>org.apache.sling.commons.mime</artifactId>
+ <version>2.1.8</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.sling</groupId>
<artifactId>org.apache.sling.testing.paxexam</artifactId>
- <version>3.1.0</version>
+ <version>4.1.2</version>
<scope>test</scope>
</dependency>
<!-- Apache Tika-->
<dependency>
- <version>1.17</version>
<groupId>org.apache.tika</groupId>
<artifactId>tika-core</artifactId>
+ <version>1.17</version>
<scope>provided</scope>
</dependency>
<!-- Apache Felix -->
<dependency>
<groupId>org.apache.felix</groupId>
<artifactId>org.apache.felix.framework</artifactId>
- <version>6.0.3</version>
+ <version>7.0.5</version>
<scope>test</scope>
</dependency>
<!-- testing -->
@@ -166,14 +166,6 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
- <executions>
- <execution>
- <goals>
- <goal>integration-test</goal>
- <goal>verify</goal>
- </goals>
- </execution>
- </executions>
<configuration>
<redirectTestOutputToFile>true</redirectTestOutputToFile>
<systemProperties>
@@ -183,6 +175,14 @@
</property>
</systemProperties>
</configuration>
+ <executions>
+ <execution>
+ <goals>
+ <goal>integration-test</goal>
+ <goal>verify</goal>
+ </goals>
+ </execution>
+ </executions>
</plugin>
<plugin>
<groupId>org.apache.servicemix.tooling</groupId>
diff --git
a/src/main/java/org/apache/sling/commons/contentdetection/ContentAwareMimeTypeService.java
b/src/main/java/org/apache/sling/commons/contentdetection/ContentAwareMimeTypeService.java
index 3ccd6ae..83f255f 100644
---
a/src/main/java/org/apache/sling/commons/contentdetection/ContentAwareMimeTypeService.java
+++
b/src/main/java/org/apache/sling/commons/contentdetection/ContentAwareMimeTypeService.java
@@ -1,26 +1,28 @@
/*
- * 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
+ * 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
+ * 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.
+ * 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.sling.commons.contentdetection;
-import org.apache.sling.commons.mime.MimeTypeService;
-
import java.io.IOException;
import java.io.InputStream;
+import org.apache.sling.commons.mime.MimeTypeService;
+
/**
* The <code>ContentAwareMimeTypeService</code> interface extends the
* {@link org.apache.sling.commons.mime.MimeTypeService} API for services
@@ -30,7 +32,6 @@ import java.io.InputStream;
* the mime type. This interface may be implemented by bundles wishing to
provide
* a mechanism to detect mime type based on the contents.
*/
-
public interface ContentAwareMimeTypeService extends MimeTypeService {
/**
* @param filename Used if <code>content</code> is <code>null</code> or if
@@ -38,7 +39,7 @@ public interface ContentAwareMimeTypeService extends
MimeTypeService {
* @param contentStream Optional stream that points to the content to
analyze,
* must support mark/reset.
* @throws IllegalArgumentException if contentStream does not support
mark/reset
- * @throws IOException if there's a problem reading the contentStream
+ * @throws IOException if there's a problem reading the contentStream
* @return the mime type
*/
String getMimeType(String filename, InputStream contentStream) throws
IOException, IllegalArgumentException;
diff --git
a/src/main/java/org/apache/sling/commons/contentdetection/FileNameExtractor.java
b/src/main/java/org/apache/sling/commons/contentdetection/FileNameExtractor.java
index 93f405b..4f49f99 100644
---
a/src/main/java/org/apache/sling/commons/contentdetection/FileNameExtractor.java
+++
b/src/main/java/org/apache/sling/commons/contentdetection/FileNameExtractor.java
@@ -1,18 +1,20 @@
/*
- * 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
+ * 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
+ * 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.
+ * 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.sling.commons.contentdetection;
diff --git
a/src/main/java/org/apache/sling/commons/contentdetection/internal/ContentAwareMimeTypeServiceImpl.java
b/src/main/java/org/apache/sling/commons/contentdetection/internal/ContentAwareMimeTypeServiceImpl.java
index aab5d01..d70b765 100644
---
a/src/main/java/org/apache/sling/commons/contentdetection/internal/ContentAwareMimeTypeServiceImpl.java
+++
b/src/main/java/org/apache/sling/commons/contentdetection/internal/ContentAwareMimeTypeServiceImpl.java
@@ -1,22 +1,26 @@
/*
- * 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
+ * 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
+ * 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.
+ * 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.sling.commons.contentdetection.internal;
+import java.io.IOException;
+import java.io.InputStream;
+
import org.apache.sling.commons.contentdetection.ContentAwareMimeTypeService;
import org.apache.sling.commons.mime.MimeTypeService;
import org.apache.tika.detect.Detector;
@@ -28,17 +32,13 @@ import org.osgi.framework.Constants;
import org.osgi.service.component.annotations.Component;
import org.osgi.service.component.annotations.Reference;
-import java.io.IOException;
-import java.io.InputStream;
-
@Component(
- property = {
- Constants.SERVICE_DESCRIPTION + "=Apache Sling Content Aware MIME Type
Service",
- Constants.SERVICE_VENDOR + "=The Apache Software Foundation",
- "detection.mode=tika"
- }
-)
-public class ContentAwareMimeTypeServiceImpl implements
ContentAwareMimeTypeService {
+ property = {
+ Constants.SERVICE_DESCRIPTION + "=Apache Sling Content Aware MIME
Type Service",
+ Constants.SERVICE_VENDOR + "=The Apache Software Foundation",
+ "detection.mode=tika"
+ })
+public class ContentAwareMimeTypeServiceImpl implements
ContentAwareMimeTypeService {
@Reference
Detector detector;
@@ -47,14 +47,14 @@ public class ContentAwareMimeTypeServiceImpl implements
ContentAwareMimeTypeSer
MimeTypeService mimeTypeService;
public String getMimeType(String filename, InputStream content) throws
IOException, IllegalArgumentException {
- if(content == null) {
+ if (content == null) {
return mimeTypeService.getMimeType(filename);
}
- if(!content.markSupported()) {
+ if (!content.markSupported()) {
throw new IllegalArgumentException("Supplied InputStream does not
support mark/reset");
}
MediaType mediaType;
- try (TemporaryResources tmp = new TemporaryResources()){
+ try (TemporaryResources tmp = new TemporaryResources()) {
TikaInputStream stream = TikaInputStream.get(content, tmp);
Metadata metadata = new Metadata();
metadata.set(Metadata.RESOURCE_NAME_KEY, filename);
diff --git
a/src/main/java/org/apache/sling/commons/contentdetection/internal/FileNameExtractorImpl.java
b/src/main/java/org/apache/sling/commons/contentdetection/internal/FileNameExtractorImpl.java
index 071bee3..d4ce72a 100644
---
a/src/main/java/org/apache/sling/commons/contentdetection/internal/FileNameExtractorImpl.java
+++
b/src/main/java/org/apache/sling/commons/contentdetection/internal/FileNameExtractorImpl.java
@@ -1,18 +1,20 @@
/*
- * 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
+ * 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
+ * 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.
+ * 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.sling.commons.contentdetection.internal;
@@ -24,11 +26,10 @@ import org.osgi.framework.Constants;
import org.osgi.service.component.annotations.Component;
@Component(
- property = {
- Constants.SERVICE_DESCRIPTION + "=Apache Sling Filename Extractor
Service",
- Constants.SERVICE_VENDOR + "=The Apache Software Foundation"
- }
-)
+ property = {
+ Constants.SERVICE_DESCRIPTION + "=Apache Sling Filename Extractor
Service",
+ Constants.SERVICE_VENDOR + "=The Apache Software Foundation"
+ })
public class FileNameExtractorImpl implements FileNameExtractor {
public String extract(String name) {
// If the name is a URL, skip the trailing query and fragment parts
@@ -66,7 +67,7 @@ public class FileNameExtractorImpl implements
FileNameExtractor {
name = name.trim();
return name;
}
-
+
protected String getDefaultEncoding() {
return "UTF-8";
}
diff --git
a/src/test/java/org/apache/sling/commons/contentdetection/internal/ContentAwareMimeTypeServiceImplTest.java
b/src/test/java/org/apache/sling/commons/contentdetection/internal/ContentAwareMimeTypeServiceImplTest.java
index 8672c33..4cd467d 100644
---
a/src/test/java/org/apache/sling/commons/contentdetection/internal/ContentAwareMimeTypeServiceImplTest.java
+++
b/src/test/java/org/apache/sling/commons/contentdetection/internal/ContentAwareMimeTypeServiceImplTest.java
@@ -1,20 +1,21 @@
/*
- * 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
+ * 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
+ * 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.
+ * 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.sling.commons.contentdetection.internal;
import java.io.ByteArrayInputStream;
@@ -55,7 +56,7 @@ public class ContentAwareMimeTypeServiceImplTest {
counterB++;
}
};
-
+
@Before
public void setup() throws NoSuchFieldException, IllegalAccessException {
contentAwareMimeTypeService = new ContentAwareMimeTypeServiceImpl();
@@ -63,14 +64,14 @@ public class ContentAwareMimeTypeServiceImplTest {
field.setAccessible(true);
field.set(contentAwareMimeTypeService, mimeTypeService);
}
-
+
@Test
- public void testGetMimeTypeByString(){
+ public void testGetMimeTypeByString() {
String mimeTypeName = "testName.txt";
final String mimeType =
contentAwareMimeTypeService.getMimeType(mimeTypeName);
Assert.assertEquals("MT_testName.txt", mimeType);
}
-
+
@Test
public void testGetExtension() {
final String ext = contentAwareMimeTypeService.getExtension("foo");
@@ -94,11 +95,8 @@ public class ContentAwareMimeTypeServiceImplTest {
@Test
public void testRegisterMimeTypeIsDelegatedB() throws IOException {
final int before = counterB;
- final InputStream is = new ByteArrayInputStream("x".getBytes());
- try {
+ try (InputStream is = new ByteArrayInputStream("x".getBytes())) {
contentAwareMimeTypeService.registerMimeType(is);
- } finally {
- is.close();
}
Assert.assertEquals("Expecting 1 call to registerMimeType(B)", before
+ 1, counterB);
}
diff --git
a/src/test/java/org/apache/sling/commons/contentdetection/internal/FileNameExtractorImplTest.java
b/src/test/java/org/apache/sling/commons/contentdetection/internal/FileNameExtractorImplTest.java
index 695d7af..b7f76ee 100644
---
a/src/test/java/org/apache/sling/commons/contentdetection/internal/FileNameExtractorImplTest.java
+++
b/src/test/java/org/apache/sling/commons/contentdetection/internal/FileNameExtractorImplTest.java
@@ -1,20 +1,21 @@
/*
- * 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
+ * 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
+ * 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.
+ * 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.sling.commons.contentdetection.internal;
import org.apache.sling.commons.contentdetection.FileNameExtractor;
@@ -24,7 +25,7 @@ import org.junit.Test;
public class FileNameExtractorImplTest {
private String defaultEncoding = new
FileNameExtractorImpl().getDefaultEncoding();
-
+
FileNameExtractor fileNameExtractor = new FileNameExtractorImpl() {
protected String getDefaultEncoding() {
return defaultEncoding;
@@ -46,14 +47,14 @@ public class FileNameExtractorImplTest {
}
@Test
- public void testDecodedURL(){
+ public void testDecodedURL() {
String rawPath = "http://example.com/demo%20test.jpg?test=true";
String expectedFileName = "demo test.jpg";
Assert.assertEquals(expectedFileName,
fileNameExtractor.extract(rawPath));
}
-
+
@Test
- public void testInvalidEncoding() throws NoSuchFieldException,
SecurityException, IllegalArgumentException, IllegalAccessException {
+ public void testInvalidEncoding() throws SecurityException,
IllegalArgumentException {
final String rawPath = "http://example.com/demo%20test.jpg?test=true";
final String oldEncoding = defaultEncoding;
final String badEncoding = "INVALID_ENCODING";
@@ -62,12 +63,14 @@ public class FileNameExtractorImplTest {
try {
fileNameExtractor.extract(rawPath);
Assert.fail("Expected an exception with encoding " +
defaultEncoding);
- } catch(RuntimeException re) {
+ } catch (RuntimeException re) {
final String msg = re.getMessage();
- Assert.assertTrue("Expected exception message to contain " +
badEncoding + " (" + msg + ")", msg.contains(badEncoding));
+ Assert.assertTrue(
+ "Expected exception message to contain " + badEncoding
+ " (" + msg + ")",
+ msg.contains(badEncoding));
}
} finally {
defaultEncoding = oldEncoding;
}
}
-}
\ No newline at end of file
+}
diff --git
a/src/test/java/org/apache/sling/commons/contentdetection/internal/it/ContentAwareMimeTypeServiceImplIT.java
b/src/test/java/org/apache/sling/commons/contentdetection/internal/it/ContentAwareMimeTypeServiceImplIT.java
index c00f1dc..a48c4f1 100644
---
a/src/test/java/org/apache/sling/commons/contentdetection/internal/it/ContentAwareMimeTypeServiceImplIT.java
+++
b/src/test/java/org/apache/sling/commons/contentdetection/internal/it/ContentAwareMimeTypeServiceImplIT.java
@@ -1,33 +1,30 @@
/*
- * 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
+ * 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
+ * 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.
+ * 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.sling.commons.contentdetection.internal.it;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
+import javax.inject.Inject;
import java.io.BufferedInputStream;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
-import javax.inject.Inject;
-
import org.apache.commons.io.IOUtils;
import org.apache.sling.commons.contentdetection.ContentAwareMimeTypeService;
import org.junit.Test;
@@ -36,13 +33,17 @@ import org.ops4j.pax.exam.junit.PaxExam;
import org.ops4j.pax.exam.spi.reactors.ExamReactorStrategy;
import org.ops4j.pax.exam.spi.reactors.PerClass;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+
@RunWith(PaxExam.class)
@ExamReactorStrategy(PerClass.class)
public class ContentAwareMimeTypeServiceImplIT extends
ContentdetectionTestSupport {
@Inject
private ContentAwareMimeTypeService contentAwareMimeTypeService;
-
+
class NonMarkableStream extends BufferedInputStream {
NonMarkableStream(InputStream is) {
super(is);
@@ -50,30 +51,36 @@ public class ContentAwareMimeTypeServiceImplIT extends
ContentdetectionTestSuppo
@Override
public synchronized void mark(int readlimit) {
+ // intentionally empty
}
@Override
public synchronized void reset() throws IOException {
+ // intentionally empty
}
@Override
public boolean markSupported() {
return false;
}
- };
-
+ }
+
@Test
public void detectFromExtension() throws IOException {
String mimeTypeName = "test.mp3";
String mimeType = "audio/mpeg";
- assertEquals("Expecting mp3 type without InputStream parameter",
- mimeType,
contentAwareMimeTypeService.getMimeType(mimeTypeName));
- assertEquals("Expecting mp3 type with null InputStream parameter",
- mimeType,
contentAwareMimeTypeService.getMimeType(mimeTypeName, null));
+ assertEquals(
+ "Expecting mp3 type without InputStream parameter",
+ mimeType,
+ contentAwareMimeTypeService.getMimeType(mimeTypeName));
+ assertEquals(
+ "Expecting mp3 type with null InputStream parameter",
+ mimeType,
+ contentAwareMimeTypeService.getMimeType(mimeTypeName, null));
}
@Test
- public void detectFromContent() throws IOException{
+ public void detectFromContent() throws IOException {
final String filename = "this-is-actually-a-wav-file.mp3";
final String path = "/" + filename;
final InputStream s = new
BufferedInputStream(getClass().getResourceAsStream(path));
@@ -89,15 +96,11 @@ public class ContentAwareMimeTypeServiceImplIT extends
ContentdetectionTestSuppo
IOUtils.closeQuietly(originalStream);
}
}
-
- @Test(expected=IllegalArgumentException.class)
- public void nonMarkableStreamDetectionShouldFail() throws IOException{
- final InputStream nms = new NonMarkableStream(new
ByteArrayInputStream("1234567890".getBytes()));
- try {
+
+ @Test(expected = IllegalArgumentException.class)
+ public void nonMarkableStreamDetectionShouldFail() throws IOException {
+ try (InputStream nms = new NonMarkableStream(new
ByteArrayInputStream("1234567890".getBytes()))) {
contentAwareMimeTypeService.getMimeType("foo.txt", nms);
- } finally {
- IOUtils.closeQuietly(nms);
}
}
-
}
diff --git
a/src/test/java/org/apache/sling/commons/contentdetection/internal/it/ContentdetectionTestSupport.java
b/src/test/java/org/apache/sling/commons/contentdetection/internal/it/ContentdetectionTestSupport.java
index 0f5691d..9f907ac 100644
---
a/src/test/java/org/apache/sling/commons/contentdetection/internal/it/ContentdetectionTestSupport.java
+++
b/src/test/java/org/apache/sling/commons/contentdetection/internal/it/ContentdetectionTestSupport.java
@@ -1,18 +1,20 @@
/*
- * 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
+ * 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
+ * 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.
+ * 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.sling.commons.contentdetection.internal.it;
@@ -31,21 +33,17 @@ public abstract class ContentdetectionTestSupport extends
TestSupport {
@Configuration
public Option[] configuration() {
return options(
- baseConfiguration(),
- slingQuickstart(),
- // Sling Content Detection
- testBundle("bundle.filename"),
- // testing
- junitBundles()
- );
+ baseConfiguration(),
+ slingQuickstart(),
+ // Sling Content Detection
+ testBundle("bundle.filename"),
+ // testing
+ junitBundles());
}
protected ModifiableCompositeOption slingQuickstart() {
final int httpPort = findFreePort();
final String workingDirectory = workingDirectory();
- return composite(
- slingQuickstartOakTar(workingDirectory, httpPort)
- );
+ return composite(slingQuickstartOakTar(workingDirectory, httpPort));
}
-
}
diff --git
a/src/test/java/org/apache/sling/commons/contentdetection/internal/it/FileNameExtractorImplIT.java
b/src/test/java/org/apache/sling/commons/contentdetection/internal/it/FileNameExtractorImplIT.java
index ccc3539..7a1e20e 100644
---
a/src/test/java/org/apache/sling/commons/contentdetection/internal/it/FileNameExtractorImplIT.java
+++
b/src/test/java/org/apache/sling/commons/contentdetection/internal/it/FileNameExtractorImplIT.java
@@ -1,24 +1,23 @@
/*
- * 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
+ * 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
+ * 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.
+ * 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.sling.commons.contentdetection.internal.it;
-import static org.junit.Assert.assertEquals;
-
import javax.inject.Inject;
import org.apache.sling.commons.contentdetection.FileNameExtractor;
@@ -28,18 +27,19 @@ import org.ops4j.pax.exam.junit.PaxExam;
import org.ops4j.pax.exam.spi.reactors.ExamReactorStrategy;
import org.ops4j.pax.exam.spi.reactors.PerClass;
+import static org.junit.Assert.assertEquals;
+
@RunWith(PaxExam.class)
@ExamReactorStrategy(PerClass.class)
-public class FileNameExtractorImplIT extends ContentdetectionTestSupport{
+public class FileNameExtractorImplIT extends ContentdetectionTestSupport {
@Inject
private FileNameExtractor fileNameExtractor;
@Test
- public void testFileNameExtractor(){
+ public void testFileNameExtractor() {
String rawPath =
"http://midches.com/images/uploads/default/demo.jpg#anchor?query=test";
String expectedFileName = "demo.jpg";
assertEquals(expectedFileName, fileNameExtractor.extract(rawPath));
}
-
}