Repository: openmeetings Updated Branches: refs/heads/3.3.x 4e35643f9 -> d096de19f
[OPENMEETINGS-1671] build should be fixed Project: http://git-wip-us.apache.org/repos/asf/openmeetings/repo Commit: http://git-wip-us.apache.org/repos/asf/openmeetings/commit/d096de19 Tree: http://git-wip-us.apache.org/repos/asf/openmeetings/tree/d096de19 Diff: http://git-wip-us.apache.org/repos/asf/openmeetings/diff/d096de19 Branch: refs/heads/3.3.x Commit: d096de19f9676125300a64fd76c0f500f32ee29d Parents: 4e35643 Author: Maxim Solodovnik <[email protected]> Authored: Thu Sep 28 10:39:54 2017 +0700 Committer: Maxim Solodovnik <[email protected]> Committed: Thu Sep 28 11:11:58 2017 +0700 ---------------------------------------------------------------------- .../openmeetings/db/util/ApplicationHelper.java | 13 +++--- .../apache/openmeetings/util/StoredFile.java | 5 +-- .../openmeetings/test/util/TestStoredFile.java | 42 ++++++++++++++++++++ .../test/webservice/AbstractWebServiceTest.java | 6 +-- .../test/webservice/TestFileService.java | 2 +- .../test/webservice/TestRoomService.java | 5 ++- 6 files changed, 59 insertions(+), 14 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/openmeetings/blob/d096de19/openmeetings-db/src/main/java/org/apache/openmeetings/db/util/ApplicationHelper.java ---------------------------------------------------------------------- diff --git a/openmeetings-db/src/main/java/org/apache/openmeetings/db/util/ApplicationHelper.java b/openmeetings-db/src/main/java/org/apache/openmeetings/db/util/ApplicationHelper.java index a4415bb..93dadb3 100644 --- a/openmeetings-db/src/main/java/org/apache/openmeetings/db/util/ApplicationHelper.java +++ b/openmeetings-db/src/main/java/org/apache/openmeetings/db/util/ApplicationHelper.java @@ -51,6 +51,7 @@ import org.springframework.web.context.support.XmlWebApplicationContext; public class ApplicationHelper { private static final Logger log = getLogger(ApplicationHelper.class, webAppRootKey); + private static final Object SYNC_OBJ = new Object(); public static WicketTester getWicketTester() { return getWicketTester(-1); @@ -81,10 +82,13 @@ public class ApplicationHelper { } public static IApplication _ensureApplication(Long langId) { - IApplication a = null; if (Application.exists()) { - a = (IApplication)Application.get(); - } else { + return (IApplication)Application.get(); + } + synchronized (SYNC_OBJ) { + if (Application.exists()) { + return (IApplication)Application.get(); + } WebApplication app = (WebApplication)Application.get(wicketApplicationName); LabelDao.initLanguageMap(); if (app == null) { @@ -110,9 +114,8 @@ public class ApplicationHelper { } else { ThreadContext.setApplication(app); } - a = (IApplication)Application.get(wicketApplicationName); + return (IApplication)Application.get(wicketApplicationName); } - return a; } public static IApplication ensureApplication(Long langId) { http://git-wip-us.apache.org/repos/asf/openmeetings/blob/d096de19/openmeetings-util/src/main/java/org/apache/openmeetings/util/StoredFile.java ---------------------------------------------------------------------- diff --git a/openmeetings-util/src/main/java/org/apache/openmeetings/util/StoredFile.java b/openmeetings-util/src/main/java/org/apache/openmeetings/util/StoredFile.java index 919336a..8ce1e34 100644 --- a/openmeetings-util/src/main/java/org/apache/openmeetings/util/StoredFile.java +++ b/openmeetings-util/src/main/java/org/apache/openmeetings/util/StoredFile.java @@ -18,12 +18,11 @@ */ package org.apache.openmeetings.util; -import static org.apache.openmeetings.util.OmFileHelper.EXTENSION_JPG; +import static org.apache.openmeetings.util.OmFileHelper.JPG_MIME_TYPE; import static org.apache.openmeetings.util.OmFileHelper.getFileExt; import static org.apache.openmeetings.util.OpenmeetingsVariables.webAppRootKey; import static org.apache.tika.metadata.TikaMetadataKeys.RESOURCE_NAME_KEY; import static org.apache.tika.mime.MediaType.application; -import static org.apache.tika.mime.MediaType.image; import java.io.File; import java.io.FileInputStream; @@ -53,7 +52,7 @@ public class StoredFile { application("x-tika-msoffice"), application("x-tika-ooxml"), application("msword") , application("vnd.wordperfect"), application("rtf"))); - private static final MediaType MIME_JPG = image(EXTENSION_JPG); + private static final MediaType MIME_JPG = MediaType.parse(JPG_MIME_TYPE); private static final Set<MediaType> PDF_TYPES = new HashSet<>(Arrays.asList(application("pdf"), application("postscript"))); private static final Set<MediaType> CHART_TYPES = new HashSet<>(/* TODO have to be tested and re-added Arrays.asList("xchart")*/); private static final Set<MediaType> AS_IS_TYPES = new HashSet<>(Arrays.asList(MIME_JPG/* TODO have to be tested and re-added, "xchart"*/)); http://git-wip-us.apache.org/repos/asf/openmeetings/blob/d096de19/openmeetings-web/src/test/java/org/apache/openmeetings/test/util/TestStoredFile.java ---------------------------------------------------------------------- diff --git a/openmeetings-web/src/test/java/org/apache/openmeetings/test/util/TestStoredFile.java b/openmeetings-web/src/test/java/org/apache/openmeetings/test/util/TestStoredFile.java new file mode 100644 index 0000000..43b6a48 --- /dev/null +++ b/openmeetings-web/src/test/java/org/apache/openmeetings/test/util/TestStoredFile.java @@ -0,0 +1,42 @@ +/* + * 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.openmeetings.test.util; + +import static org.apache.openmeetings.util.OmFileHelper.getDefaultProfilePicture; +import static org.junit.Assert.assertTrue; + +import java.io.File; +import java.io.FileNotFoundException; +import java.io.IOException; + +import org.apache.openmeetings.test.AbstractJUnitDefaults; +import org.apache.openmeetings.util.StoredFile; +import org.junit.Test; + +public class TestStoredFile extends AbstractJUnitDefaults { + @Test + public void testJpeg() throws FileNotFoundException, IOException { + File f = getDefaultProfilePicture(); + for (String ext : new String[] {null, "txt", "png"}) { + StoredFile sf = new StoredFile("test image", ext, f); + assertTrue("Type should be detected as image", sf.isImage()); + assertTrue("Type should be detected as image", sf.isAsIs()); + } + } +} http://git-wip-us.apache.org/repos/asf/openmeetings/blob/d096de19/openmeetings-web/src/test/java/org/apache/openmeetings/test/webservice/AbstractWebServiceTest.java ---------------------------------------------------------------------- diff --git a/openmeetings-web/src/test/java/org/apache/openmeetings/test/webservice/AbstractWebServiceTest.java b/openmeetings-web/src/test/java/org/apache/openmeetings/test/webservice/AbstractWebServiceTest.java index 0068c56..598de43 100644 --- a/openmeetings-web/src/test/java/org/apache/openmeetings/test/webservice/AbstractWebServiceTest.java +++ b/openmeetings-web/src/test/java/org/apache/openmeetings/test/webservice/AbstractWebServiceTest.java @@ -144,15 +144,15 @@ public class AbstractWebServiceTest extends AbstractJUnitDefaults { u.setId(user.getId()); } - public CallResult<FileItemDTO> createVerifiedFile(File fsFile) throws IOException { + public CallResult<FileItemDTO> createVerifiedFile(File fsFile, String name, BaseFileItem.Type type) throws IOException { ServiceResult r = login(); FileItemDTO f1 = null; try (InputStream is = new FileInputStream(fsFile)) { FileItemDTO file = new FileItemDTO(); - file.setName("test.txt"); + file.setName(name); file.setHash(UUID.randomUUID().toString()); - file.setType(BaseFileItem.Type.Presentation); + file.setType(type); List<Attachment> atts = new ArrayList<>(); atts.add(new Attachment("file", MediaType.APPLICATION_JSON, file)); atts.add(new Attachment("stream", MediaType.APPLICATION_OCTET_STREAM, is)); http://git-wip-us.apache.org/repos/asf/openmeetings/blob/d096de19/openmeetings-web/src/test/java/org/apache/openmeetings/test/webservice/TestFileService.java ---------------------------------------------------------------------- diff --git a/openmeetings-web/src/test/java/org/apache/openmeetings/test/webservice/TestFileService.java b/openmeetings-web/src/test/java/org/apache/openmeetings/test/webservice/TestFileService.java index ef0bba2..d4c7ad5 100644 --- a/openmeetings-web/src/test/java/org/apache/openmeetings/test/webservice/TestFileService.java +++ b/openmeetings-web/src/test/java/org/apache/openmeetings/test/webservice/TestFileService.java @@ -47,7 +47,7 @@ public class TestFileService extends AbstractWebServiceTest { Graphics g = image.getGraphics(); g.drawString("Hello World!!!", 10, 20); ImageIO.write(image, "jpg", img); - CallResult<FileItemDTO> cr = createVerifiedFile(img); + CallResult<FileItemDTO> cr = createVerifiedFile(img, "test.txt", BaseFileItem.Type.Presentation); assertEquals("Type should be Image", BaseFileItem.Type.Image, cr.getObj().getType()); assertEquals("Width should be determined", width, cr.getObj().getWidth()); assertEquals("Height should be Image", height, cr.getObj().getHeight()); http://git-wip-us.apache.org/repos/asf/openmeetings/blob/d096de19/openmeetings-web/src/test/java/org/apache/openmeetings/test/webservice/TestRoomService.java ---------------------------------------------------------------------- diff --git a/openmeetings-web/src/test/java/org/apache/openmeetings/test/webservice/TestRoomService.java b/openmeetings-web/src/test/java/org/apache/openmeetings/test/webservice/TestRoomService.java index c308779..dc13282 100644 --- a/openmeetings-web/src/test/java/org/apache/openmeetings/test/webservice/TestRoomService.java +++ b/openmeetings-web/src/test/java/org/apache/openmeetings/test/webservice/TestRoomService.java @@ -19,6 +19,7 @@ package org.apache.openmeetings.test.webservice; import static javax.ws.rs.core.MediaType.APPLICATION_FORM_URLENCODED; +import static org.apache.openmeetings.util.OmFileHelper.getDefaultProfilePicture; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotNull; @@ -33,8 +34,8 @@ import org.apache.openmeetings.db.dto.basic.ServiceResult; import org.apache.openmeetings.db.dto.file.FileItemDTO; import org.apache.openmeetings.db.dto.room.RoomDTO; import org.apache.openmeetings.db.dto.room.RoomFileDTO; +import org.apache.openmeetings.db.entity.file.BaseFileItem; import org.apache.openmeetings.db.entity.room.Room; -import org.apache.openmeetings.util.OmFileHelper; import org.junit.Test; public class TestRoomService extends AbstractWebServiceTest { @@ -150,7 +151,7 @@ public class TestRoomService extends AbstractWebServiceTest { @Test public void testCreateWithFiles2() throws IOException { //lets create real file - CallResult<FileItemDTO> fileCall = createVerifiedFile(OmFileHelper.getDefaultProfilePicture()); + CallResult<FileItemDTO> fileCall = createVerifiedFile(getDefaultProfilePicture(), "img.jpg", BaseFileItem.Type.Image); Room.Type type = Room.Type.restricted; String name = "Unit Test Ext Room4";
