/modules/plugin/mongodb/src/test/java/org/geotools/data/mongodb/MongoUtilTest.java

https://github.com/geotools/geotools · Java · 73 lines · 43 code · 12 blank · 18 comment · 0 complexity · ed4264d7f730ffe7e1b0ad74ee07285c MD5 · raw file

  1. /*
  2. * GeoTools - The Open Source Java GIS Toolkit
  3. * http://geotools.org
  4. *
  5. * (C) 2015, Open Source Geospatial Foundation (OSGeo)
  6. * (C) 2014-2015, Boundless
  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;
  11. * version 2.1 of the License.
  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. package org.geotools.data.mongodb;
  19. import static org.hamcrest.CoreMatchers.equalTo;
  20. import static org.hamcrest.CoreMatchers.is;
  21. import static org.hamcrest.CoreMatchers.nullValue;
  22. import static org.hamcrest.MatcherAssert.assertThat;
  23. import static org.junit.Assert.assertTrue;
  24. import com.mongodb.BasicDBObject;
  25. import com.mongodb.DBObject;
  26. import java.io.IOException;
  27. import org.hamcrest.CoreMatchers;
  28. import org.junit.Test;
  29. /** @author tkunicki@boundlessgeo.com */
  30. public class MongoUtilTest {
  31. public MongoUtilTest() {}
  32. @Test
  33. public void set() {
  34. DBObject dbo = new BasicDBObject();
  35. MongoUtil.setDBOValue(dbo, "root.child1", 1d);
  36. Object result = MongoUtil.getDBOValue(dbo, "root.child1");
  37. assertThat(result, is(CoreMatchers.instanceOf(Double.class)));
  38. assertThat((Double) result, is(equalTo(1d)));
  39. MongoUtil.setDBOValue(dbo, "root.child2", "one");
  40. result = MongoUtil.getDBOValue(dbo, "root.child2");
  41. assertThat(result, is(CoreMatchers.instanceOf(String.class)));
  42. assertThat((String) result, is(equalTo("one")));
  43. result = MongoUtil.getDBOValue(dbo, "root.doesnotexists");
  44. assertThat(result, is(nullValue()));
  45. result = MongoUtil.getDBOValue(dbo, "bugusroot.neglectedchild");
  46. assertThat(result, is(nullValue()));
  47. }
  48. @Test
  49. public void testFileNameExtractionFromUrl() throws IOException {
  50. String url1 = "http://www.mock.com/filename.zip?param=1&query=44";
  51. assertTrue(MongoUtil.extractFilesNameFromUrl(url1).equalsIgnoreCase("filename.zip"));
  52. String url2 = "https://mock.url.com/filename.zip";
  53. assertTrue(MongoUtil.extractFilesNameFromUrl(url2).equalsIgnoreCase("filename.zip"));
  54. String url3 = "https://mock.url.com/filename.json?param=1&query=44";
  55. assertTrue(MongoUtil.extractFilesNameFromUrl(url3).equalsIgnoreCase("filename.json"));
  56. String url4 = "https://mock.url.com/filename.json";
  57. assertTrue(MongoUtil.extractFilesNameFromUrl(url4).equalsIgnoreCase("filename.json"));
  58. String url5 = "https://mock.url.com/path1/path2/filename.json";
  59. assertTrue(MongoUtil.extractFilesNameFromUrl(url5).equalsIgnoreCase("filename.json"));
  60. }
  61. }