static MimeType calcExpectedMediaType(AnnotationSource primarySource, ModelBuilder builder ) { XmlMimeType xmt = primarySource.readAnnotation(XmlMimeType.class); if(xmt==null) return null; try { return new MimeType(xmt.value()); } catch (MimeTypeParseException e) { builder.reportError(new IllegalAnnotationException( Messages.ILLEGAL_MIME_TYPE.format(xmt.value(),e.getMessage()), xmt )); return null; } }
@Override public BufferedReader getReader() throws IOException { if (null == servletReader) { if (null != servletInputStream) { throw new IllegalStateException("Cannot call getReader() after getInputStream()"); } try { servletReader = new BufferedReader(new InputStreamReader( inputStream, null == getOrParseCharacterEncodingImpl() ? UTF8 : characterEncoding )); } catch (MimeTypeParseException e) { throw new UnsupportedEncodingException(format("Couldn't parse encoding from mime type: %s", e.getMessage())); } } return servletReader; }
@Test public void testUnmarshalJsonContent() throws MimeTypeParseException { // PREPARE final Data data = new Data("BookAddedEvent", new EnhancedMimeType("application/json; encoding=utf-8"), "{\"name\":\"Shining\",\"author\":\"Stephen King\"}"); // TEST final JsonObject event = data.unmarshalContent(null); // VERIFY assertThat(event.getString("name")).isEqualTo("Shining"); assertThat(event.getString("author")).isEqualTo("Stephen King"); }
@Test public void testValueOfXml() throws MimeTypeParseException { // PREPARE final BookAddedEvent event = new BookAddedEvent("Shining", "Stephen King"); // TEST final Data data = Data.valueOf("BookAddedEvent", event); // VERIFY assertThat(data.getType()).isEqualTo("BookAddedEvent"); assertThat(data.getMimeType()).isEqualTo( new EnhancedMimeType("application/xml; encoding=utf-8")); assertThat(data.getContent()).isEqualTo(Units4JUtils.XML_PREFIX + "<book-added-event><name>Shining</name><author>Stephen King</author></book-added-event>"); assertThat(data.isXml()).isTrue(); assertThat(data.isJson()).isFalse(); }
@Test public void testValueOfJson() throws MimeTypeParseException { // PREPARE final JsonObject event = Json.createObjectBuilder() .add("name", "Shining").add("author", "Stephen King").build(); // TEST final Data data = Data.valueOf("BookAddedEvent", event); System.out.println(event.toString()); // VERIFY assertThat(data.getType()).isEqualTo("BookAddedEvent"); assertThat(data.getMimeType()).isEqualTo( new EnhancedMimeType("application/json; encoding=utf-8")); assertThat(data.getContent()).isEqualTo( "{\"name\":\"Shining\",\"author\":\"Stephen King\"}"); assertThat(data.isXml()).isFalse(); assertThat(data.isJson()).isTrue(); }
@Test public void testConstrcutionAllArgs() throws MimeTypeParseException { // PREPARE & TEST final Map<String, String> params = new HashMap<String, String>(); params.put("a", "1"); final EnhancedMimeType testee = new EnhancedMimeType("application", "json", Charset.forName("utf-8"), "1.0.2", params); // VERIFY assertThat(testee.getPrimaryType()).isEqualTo("application"); assertThat(testee.getSubType()).isEqualTo("json"); assertThat(testee.getEncoding()).isEqualTo(Charset.forName("utf-8")); assertThat(testee.getParameter(EnhancedMimeType.ENCODING)).isEqualTo( "UTF-8"); assertThat(testee.getVersion()).isEqualTo("1.0.2"); assertThat(testee.getParameter(EnhancedMimeType.VERSION)).isEqualTo( "1.0.2"); assertThat(testee.getParameter("a")).isEqualTo("1"); assertThat(testee.getParameters().size()).isEqualTo(3); }
@Test public void testXmlXml() throws IOException, MimeTypeParseException { // PREPARE final SerializedDataType dataType = new SerializedDataType(MyEvent.TYPE.asBaseType()); final EnhancedMimeType mimeType = new EnhancedMimeType("application/xml"); final DeserializerRegistry registry = createRegistry(); final Node node = parse("/event-xml-xml-xml.xml", "/Event/Data"); // TEST final Object obj = new ESHttpXmlUnmarshaller().unmarshal(registry, dataType, mimeType, node); // VERIFY assertThat(obj).isInstanceOf(MyEvent.class); final MyEvent event = (MyEvent) obj; assertThat(event.getId()).isEqualTo("68616d90-cf72-4c2a-b913-32bf6e6506ed"); assertThat(event.getDescription()).isEqualTo("Hello, XML!"); }
@Test public void testXmlOther() throws IOException, MimeTypeParseException { // PREPARE final SerializedDataType dataType = new SerializedDataType(MyEvent.TYPE.asBaseType()); final EnhancedMimeType mimeType = new EnhancedMimeType( "application/json; version=1; encoding=utf-8; transfer-encoding=base64"); final DeserializerRegistry registry = createRegistry(); final Node node = parse("/event-xml-xml-other.xml", "/Event/Data"); // TEST final Object obj = new ESHttpXmlUnmarshaller().unmarshal(registry, dataType, mimeType, node); // VERIFY assertThat(obj).isInstanceOf(JsonObject.class); final JsonObject event = (JsonObject) obj; assertThat(event.getString("id")).isEqualTo("68616d90-cf72-4c2a-b913-32bf6e6506e"); assertThat(event.getString("description")).isEqualTo("Hello, JSON!"); }
@Test public void testJsonJson() throws IOException, MimeTypeParseException { // PREPARE final SerializedDataType dataType = new SerializedDataType(MyEvent.TYPE.asBaseType()); final EnhancedMimeType mimeType = new EnhancedMimeType("application/json"); final DeserializerRegistry registry = createRegistry(); final JsonObject jsonObj = parse("/event-json-json-json.json", "$.Data"); // TEST final Object obj = new ESHttpJsonUnmarshaller().unmarshal(registry, dataType, mimeType, jsonObj); // VERIFY assertThat(obj).isInstanceOf(JsonObject.class); final JsonObject event = (JsonObject) obj; assertThat(event.getString("id")).isEqualTo("b2a936ce-d479-414f-b67f-3df4da383d47"); assertThat(event.getString("description")).isEqualTo("Hello, JSON!"); }
@Test public void testJsonOther() throws IOException, MimeTypeParseException { // PREPARE final SerializedDataType dataType = new SerializedDataType(MyEvent.TYPE.asBaseType()); final EnhancedMimeType mimeType = new EnhancedMimeType( "application/xml; version=1; encoding=utf-8; transfer-encoding=base64"); final DeserializerRegistry registry = createRegistry(); final JsonObject jsonObj = parse("/event-json-json-other.json", "$.Data"); // TEST final Object obj = new ESHttpJsonUnmarshaller().unmarshal(registry, dataType, mimeType, jsonObj); // VERIFY assertThat(obj).isInstanceOf(MyEvent.class); final MyEvent event = (MyEvent) obj; assertThat(event.getId()).isEqualTo("bd58da40-9249-4b42-a077-10455b483c80"); assertThat(event.getDescription()).isEqualTo("Hello, XML!"); }
@Override public String getImageType() throws TileStoreException { try { final MimeType mimeType = new MimeType(Files.probeContentType(this.rawImage.toPath())); if(mimeType.getPrimaryType().toLowerCase().equals("image")) { return mimeType.getSubType(); } return null; } catch(final MimeTypeParseException | IOException ex) { throw new TileStoreException(ex); } }
/** * Create a set of {@link MimeType} objects from their corresponding string * designations * * @param types * Mime type strings * @return A set of MimeType objects */ public static Set<MimeType> createMimeTypeSet(final String... types) { if(types == null) { throw new IllegalArgumentException("The mime type strings cannot be null."); } final Set<MimeType> imageFormats = new HashSet<>(); for(final String type : types) { try { imageFormats.add(new MimeType(type)); } catch(final MimeTypeParseException | NullPointerException ex) { // This method was specifically created to avoid checked exceptions } } return imageFormats; }
@Test public void createMimeTypeSetVerify() throws MimeTypeParseException { final String[] mimeTypeStrings = {"image/png", "image/jpeg", null, "video/avi", "image/bmp", "text/plain"}; final Set<MimeType> expectedMimeTypes = new HashSet<>(Arrays.asList(new MimeType("image/png"), new MimeType("image/jpeg"), new MimeType("video/avi"), new MimeType("image/bmp"), new MimeType("text/plain"))); final Set<MimeType> returnedMimeTypes = MimeTypeUtility.createMimeTypeSet(mimeTypeStrings); MimeTypeUtilityTest.assertCreateMimeTypes(expectedMimeTypes, returnedMimeTypes); }
/** * Tests if GeoPackageWriter will throw an Illegal argumentException when * adding a tile with a null value for buffered image */ @Test(expected = IllegalArgumentException.class) public void addTileIllegalArgumentException2() throws SQLException, MimeTypeParseException, TileStoreException { final File testFile = this.getRandomFile(6); try(final GeoPackageWriter gpkgWriter = new GeoPackageWriter(testFile, new CoordinateReferenceSystem("EPSG", 4326), "foo", "identifier", "description", new BoundingBox(0.0,0.0,90.0,90.0), new ZoomTimesTwo(0, 0, 4, 2), new MimeType("image/jpeg"), null)) { gpkgWriter.addTile(new CrsCoordinate(30.0,20.0, "epsg", 4326), 0, null); fail("Expected GeoPackageWriter to throw an IllegalArgumentException if a user puts in a null value for the parameter image."); } finally { deleteFile(testFile); } }
/** * Tests if GeoPackageWriter will throw an Illegal argumentException when * adding a tile with a null value for buffered image */ @Test(expected = IllegalArgumentException.class) public void addTileIllegalArgumentException4() throws SQLException, MimeTypeParseException, TileStoreException { final File testFile = this.getRandomFile(6); try(final GeoPackageWriter gpkgWriter = new GeoPackageWriter(testFile, new CoordinateReferenceSystem("EPSG", 4326), "foo", "identifier", "description", new BoundingBox(0.0,0.0,90.0,90.0), new ZoomTimesTwo(0, 0, 4, 2), new MimeType("image/jpeg"), null)) { gpkgWriter.addTile(new CrsCoordinate(30.0, 20.0, "epsg", 3395), 0, new BufferedImage(256,256, BufferedImage.TYPE_INT_ARGB)); fail("Expected GeoPackageWriter to throw an IllegalArgumentException if a user adds a tile that is a different crs coordinate reference system than the profile."); } finally { deleteFile(testFile); } }
/** * Tests if GeoPackageWriter throws an IllegalArgumentException * when trying to create a GeoPackageWriter with a tileSet parameter * value of null */ @Test(expected = TileStoreException.class) @SuppressWarnings("ExpectedExceptionNeverThrown") // Intellij bug? public void geoPackageWriterIllegalArgumentException() throws TileStoreException, SQLException, MimeTypeParseException { final File testFile = this.getRandomFile(8); try(final GeoPackageWriter ignored = new GeoPackageWriter(testFile, new CoordinateReferenceSystem("EPSG", 4326), null, "identifier", "description", new BoundingBox(0.0,0.0,90.0,90.0), new ZoomTimesTwo(0, 0, 4, 2), new MimeType("image/jpeg"), null)) { fail("Expected GeoPackageWriter to throw an IllegalArgumentException if a user puts in a null value for the parameter tile set table name."); } finally { deleteFile(testFile); } }
/** * Tests if GeoPackageWriter throws an IllegalArgumentException * when trying to create a GeoPackageWriter with a GeoPackage parameter * value of null */ @Test(expected = IllegalArgumentException.class) public void geoPackageWriterIllegalArgumentException2() throws TileStoreException, SQLException, MimeTypeParseException { final File testFile = this.getRandomFile(8); try(final GeoPackageWriter ignored = new GeoPackageWriter(null, new CoordinateReferenceSystem("EPSG", 4326), "foo", "identifier", "description", new BoundingBox(0.0,0.0,90.0,90.0), new ZoomTimesTwo(0, 0, 4, 2), new MimeType("image/jpeg"), null)) { fail("Expected GeoPackageWriter to throw an IllegalArgumentException if a user puts in a null value for the parameter geo package file."); } finally { deleteFile(testFile); } }
/** * Tests if GeoPackageWriter throws an IllegalArgumentException * when trying to create a GeoPackageWriter with an unsupported output * image format */ @Test(expected = IllegalArgumentException.class) public void geoPackageWriterIllegalArgumentException4() throws TileStoreException, SQLException, MimeTypeParseException { final File testFile = this.getRandomFile(8); try(final GeoPackageWriter ignored = new GeoPackageWriter(testFile, new CoordinateReferenceSystem("EPSG", 4326), "foo", "identifier", "description", new BoundingBox(0.0,0.0,90.0,90.0), new ZoomTimesTwo(0, 0, 4, 2), new MimeType("text/xml"), null)) { fail("Expected GeoPackageWriter to throw an IllegalArgumentException if a user puts in an unsupported image output format."); } finally { deleteFile(testFile); } }
/** * Tests if GeoPackageWriter throws an IllegalArgumentException * when trying to create a GeoPackageWriter with a null value * for crs */ @Test(expected = IllegalArgumentException.class) public void geoPackageWriterIllegalArgumentException5() throws TileStoreException, SQLException, MimeTypeParseException { final File testFile = this.getRandomFile(8); try(final GeoPackageWriter ignored = new GeoPackageWriter(testFile, null, "foo", "identifier", "description", new BoundingBox(0.0,0.0,90.0,90.0), new ZoomTimesTwo(0, 0, 4, 2), new MimeType("image/jpeg"), null)) { fail("Expected GeoPackageWriter to throw an IllegalArgumentException if a user puts in null for the crs."); } finally { deleteFile(testFile); } }
/** * Tests if an Illegal argument exception is thrown when passing in a null value * for TileOrigin to tileToCrsCoordinate */ @Test(expected = IllegalArgumentException.class) public void geoPackageWriterTileToCrsCoordinateIllegalArgumentException() throws SQLException, MimeTypeParseException, TileStoreException { final File testFile = this.getRandomFile(8); final CoordinateReferenceSystem crs = new CoordinateReferenceSystem("EPSG", 4326); final BoundingBox bBox = new BoundingBox(0.0,0.0,0.0,0.0); final TileScheme tileScheme = new ZoomTimesTwo(0, 10, 2, 4); try(final GeoPackageWriter gpkgWriter = new GeoPackageWriter(testFile, crs, "tableName","identifier", "description", bBox, tileScheme, new MimeType("image/png"), null)) { gpkgWriter.tileToCrsCoordinate(1, 1, 1, null); fail("Expected an IllegalArgumentException when giving a null value for TileOrigin."); } finally { deleteFile(testFile); } }
/** * Tests if TmsWriter can return the expected boundingBox for a particular tile * @throws MimeTypeParseException */ @Test public void verifyTileBoundingBox() throws MimeTypeParseException { final Path tmsDir = TmsUtility.createTMSFolderGeodetic(this.tempFolder, 3); try(final TmsWriter tmsWriter = new TmsWriter(new CoordinateReferenceSystem("EPSG", 4326), tmsDir, new MimeType("image/png"))) { final int column = 3; final int row = 2; final int zoom = 3; final BoundingBox bBoxReturned = tmsWriter.getTileBoundingBox(column, row, zoom); final BoundingBox bBoxExpected = getExpectedBoundingBox(column, row, zoom, new GlobalGeodeticCrsProfile()); assertBoundingBoxesEqual(bBoxExpected, bBoxReturned); } }
/** * Tests if GeoPackage Schema throws * an IllegalArgumentException when adding * a data column with an empty string for columnName */ @Test(expected = IllegalArgumentException.class) public void addDataColumnIllegalArgumentException3() throws ClassNotFoundException, IOException, SQLException, ConformanceException, MimeTypeParseException { final File testFile = TestUtility.getRandomFile(); try(final GeoPackage gpkg = new GeoPackage(testFile, OpenMode.Create)) { final Content table = gpkg.tiles().addTileSet("tableName", "identifier", "description", new BoundingBox(0.0,0.0,180.0,90.0), gpkg.core().getSpatialReferenceSystem(4326)); final String name = "name"; final String title = "title"; final String description = "description"; final MimeType mimeType = new MimeType("image/png"); final String constraintName = "constraint_name"; gpkg.schema().addDataColumn(table, "", name, title, description, mimeType, constraintName); fail("Expected GeoPackage to throw an IllegalArgumentException when trying to add a datacolumn and columnName is null."); } }
/** * Tests if GeoPackage Schema throws * an IllegalArgumentException when adding * a data column with a null value for columnName */ @Test(expected = IllegalArgumentException.class) public void addDataColumnIllegalArgumentException2() throws ClassNotFoundException, IOException, SQLException, ConformanceException, MimeTypeParseException { final File testFile = TestUtility.getRandomFile(); try(final GeoPackage gpkg = new GeoPackage(testFile, OpenMode.Create)) { final Content table = gpkg.tiles().addTileSet("tableName", "identifier", "description", new BoundingBox(0.0,0.0,180.0,90.0), gpkg.core().getSpatialReferenceSystem(4326)); final String name = "name"; final String title = "title"; final String description = "description"; final MimeType mimeType = new MimeType("image/png"); final String constraintName = "constraint_name"; gpkg.schema().addDataColumn(table, null, name, title, description, mimeType, constraintName); fail("Expected GeoPackage to throw an IllegalArgumentException when trying to add a datacolumn and columnName is null."); } }
@Test public void verifyTileToCrsCoordinate() throws MimeTypeParseException { final Path tmsDir = TmsUtility.createTMSFolderMercator(this.tempFolder, 3); try(final TmsWriter tmsWriter = new TmsWriter(new CoordinateReferenceSystem("EPSG", 3857), tmsDir, new MimeType("image/png"))) { final int column = 2; final int row = 7; final int zoom = 3; final TileOrigin corner = TileOrigin.UpperRight; final CrsProfile crsProfile = new SphericalMercatorCrsProfile(); final CrsCoordinate crsCoordReturned = tmsWriter.tileToCrsCoordinate (column, row, zoom, corner); final CrsCoordinate crsCoordExpected = getExpectedCrsCoordinate((column + 1), (row + 1), zoom, crsProfile); //since it is upper right // add one to both column and row assertEquals(crsCoordExpected, crsCoordReturned); } }
@Test public void verifyTileToCrsCoordinate2() throws MimeTypeParseException { final Path tmsDir = TmsUtility.createTMSFolderMercator(this.tempFolder, 3); try(final TmsWriter tmsWriter = new TmsWriter(new CoordinateReferenceSystem("EPSG", 3857), tmsDir, new MimeType("image/png"))) { final int column = 2; final int row = 7; final int zoom = 3; final TileOrigin corner = TileOrigin.UpperLeft; final CrsProfile crsProfile = new SphericalMercatorCrsProfile(); final CrsCoordinate crsCoordReturned = tmsWriter.tileToCrsCoordinate (column, row, zoom, corner); final CrsCoordinate crsCoordExpected = getExpectedCrsCoordinate(column, (row + 1), zoom, crsProfile); //since it is upper // add one to row assertEquals(crsCoordExpected, crsCoordReturned); } }
@Test public void verifyTileToCrsCoordinate3() throws MimeTypeParseException { final Path tmsDir = TmsUtility.createTMSFolderMercator(this.tempFolder, 3); try(final TmsWriter tmsWriter = new TmsWriter(new CoordinateReferenceSystem("EPSG", 3857), tmsDir, new MimeType("image/png"))) { final int column = 2; final int row = 7; final int zoom = 3; final TileOrigin corner = TileOrigin.LowerRight; final CrsProfile crsProfile = new SphericalMercatorCrsProfile(); final CrsCoordinate crsCoordReturned = tmsWriter.tileToCrsCoordinate(column, row, zoom, corner); final CrsCoordinate crsCoordExpected = getExpectedCrsCoordinate((column + 1), row, zoom, crsProfile); //since it is right // add one to column assertEquals(crsCoordExpected, crsCoordReturned); } }
@Test public void verifyTileToCrsCoordinate4() throws MimeTypeParseException { final Path tmsDir = TmsUtility.createTMSFolderMercator(this.tempFolder, 3); try(final TmsWriter tmsWriter = new TmsWriter(new CoordinateReferenceSystem("EPSG", 3857), tmsDir, new MimeType("image/png"))) { final int column = 2; final int row = 7; final int zoom = 3; final TileOrigin corner = TileOrigin.LowerLeft; final CrsProfile crsProfile = new SphericalMercatorCrsProfile(); final CrsCoordinate crsCoordReturned = tmsWriter.tileToCrsCoordinate(column, row, zoom, corner); final CrsCoordinate crsCoordExpected = getExpectedCrsCoordinate(column, row, zoom, crsProfile); assertEquals(crsCoordExpected, crsCoordReturned); } }
@Test public void verifyCrsToTileCoordinate() throws MimeTypeParseException { final Path tmsDir = TmsUtility.createTMSFolderMercator(this.tempFolder, 3); try(final TmsWriter tmsWriter = new TmsWriter(new CoordinateReferenceSystem("EPSG", 3857), tmsDir, new MimeType("image/png"), new ImageWriteParam(null))) { final int zoom = 3; final Coordinate<Integer> tileCoordinateExpected = new Coordinate<>(3, 5); final CrsCoordinate crsCoordinate = tmsWriter.tileToCrsCoordinate(tileCoordinateExpected.getX(), tileCoordinateExpected.getY(), zoom, TmsWriter.Origin); final Coordinate<Integer> tileCoordinateReturned = tmsWriter.crsToTileCoordinate(crsCoordinate, zoom); assertEquals(tileCoordinateExpected, tileCoordinateReturned); } }
@Test public void verifyCrsToTileCoordinate2() throws MimeTypeParseException { final Path tmsDir = TmsUtility.createTMSFolderGeodetic(this.tempFolder, 3); try(final TmsWriter tmsWriter = new TmsWriter(new CoordinateReferenceSystem("EPSG", 4326), tmsDir, new MimeType("image/png"), null)) { final int zoom = 2; final Coordinate<Integer> tileCoordinateExpected = new Coordinate<>(0, 1); final CrsCoordinate crsCoordinate = tmsWriter.tileToCrsCoordinate(tileCoordinateExpected.getX(), tileCoordinateExpected.getY(), zoom, tmsWriter.getTileOrigin()); final Coordinate<Integer> tileCoordinateReturned = tmsWriter.crsToTileCoordinate(crsCoordinate, zoom); assertEquals(tileCoordinateExpected, tileCoordinateReturned); } }
@Test(expected = IllegalArgumentException.class) public void addTileIllegalArgumentException2() throws MimeTypeParseException, TileStoreException { final Path tmsDir = TmsUtility.createTMSFolderGeodetic(this.tempFolder, 3); final CrsProfile crs = CrsProfileFactory.create("EPSG", 4326); try(final TmsWriter tmsWriter = new TmsWriter(crs.getCoordinateReferenceSystem(), tmsDir, new MimeType("image/png"))) { final CrsCoordinate crsCoordinate = new CrsCoordinate(getExpectedCrsCoordinate(0, 2, 3, crs), crs.getCoordinateReferenceSystem()); tmsWriter.addTile(crsCoordinate, 3, null); fail("Expected an IllegalArgumentException when passing a null value for image"); } }
@Test(expected = IllegalArgumentException.class) public void addTileIllegalArgumentException3() throws MimeTypeParseException, TileStoreException { final Path tmsDir = TmsUtility.createTMSFolderGeodetic(this.tempFolder, 3); try(final TmsWriter tmsWriter = new TmsWriter(new CoordinateReferenceSystem("EPSG", 4326), tmsDir, new MimeType("image/png"))) { final CrsCoordinate crsCoordinate = new CrsCoordinate(getExpectedCrsCoordinate(0, 2, 3, new SphericalMercatorCrsProfile()), new SphericalMercatorCrsProfile().getCoordinateReferenceSystem()); tmsWriter.addTile(crsCoordinate, 3, createImage()); fail("Expected an IllegalArgumentException when passing CrsCoordinate with a different coordinateReferenceSystem than the TMS."); } }
/** * Tests if GeoPackageMetadata can add metadata * and verify it returns the expected values */ @Test public void addMetadataVerify() throws ClassNotFoundException, ConformanceException, IOException, SQLException, URISyntaxException, MimeTypeParseException { final File testFile = TestUtility.getRandomFile(); try(GeoPackage gpkg = new GeoPackage(testFile, OpenMode.Create)) { final Scope scope = Scope.Dataset; final URI standardUri = new URI("http://www.geopackage.org/spec/#metadata_scopes"); final MimeType mimeType = new MimeType("text/xml"); final String metadata = ""; final Metadata metadataReturned =gpkg.metadata().addMetadata(scope, standardUri, mimeType, metadata); gpkg.metadata().addMetadata(scope, standardUri, mimeType, metadata); assertTrue("Metadata returned does not have the expected values.", metadataReturned.getScope() .equalsIgnoreCase(scope.toString()) && metadataReturned.getStandardUri().equalsIgnoreCase(standardUri.toString()) && metadataReturned.getMimeType() .equalsIgnoreCase(mimeType.toString()) && metadataReturned.getMetadata() .equalsIgnoreCase(metadata)); } }
/** * Tests if an IllegalArgumentException is thrown * when adding metadata with scope as a null parameter */ @Test(expected = IllegalArgumentException.class) public void addMetadataIllegalArgumentException() throws ClassNotFoundException, ConformanceException, IOException, SQLException, URISyntaxException, MimeTypeParseException { final File testFile = TestUtility.getRandomFile(); try(GeoPackage gpkg = new GeoPackage(testFile, OpenMode.Create)) { final URI standardUri = new URI("http://www.geopackage.org/spec/#metadata_scopes"); final MimeType mimeType = new MimeType("text/xml"); final String metadata = ""; gpkg.metadata().addMetadata(null, standardUri, mimeType, metadata); fail("Expected GeoPackage Metadata to throw an IllegalArgumentException when passing a null value for scope when using the method addMetadata"); } }
/** * Tests if an IllegalArgumentException is thrown * when adding metadata with uri as a null parameter */ @Test(expected = IllegalArgumentException.class) public void addMetadataIllegalArgumentException2() throws ClassNotFoundException, IOException, SQLException, ConformanceException, MimeTypeParseException { final File testFile = TestUtility.getRandomFile(); try(GeoPackage gpkg = new GeoPackage(testFile, OpenMode.Create)) { final Scope scope = Scope.Dataset; final MimeType mimeType = new MimeType("text/xml"); final String metadata = ""; gpkg.metadata().addMetadata(scope, null, mimeType, metadata); fail("Expected GeoPackage Metadata to throw an IllegalArgumentException when passing a null value for uri when using the method addMetadata"); } }