Java Code Examples for junit.framework.TestCase#assertNotNull()

The following examples show how to use junit.framework.TestCase#assertNotNull() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Uninstaller.java    From netbeans with Apache License 2.0 6 votes vote down vote up
@org.junit.Test
public void testUninstaller() {
    TestData data = new TestData(Logger.getLogger("global"));

    try {
        String wd = System.getenv("WORKSPACE");
        TestCase.assertNotNull(wd);
        data.setWorkDir(new File(wd));
    } catch (IOException ex) {
        TestCase.fail("Can not get WorkDir");
    }


    System.setProperty("nbi.dont.use.system.exit", "true");
    System.setProperty("nbi.utils.log.to.console", "false");
    System.setProperty("servicetag.allow.register", "false");
    System.setProperty("show.uninstallation.survey", "false");
    System.setProperty("user.home", data.getWorkDirCanonicalPath());

    Utils.phaseFive(data);
}
 
Example 2
Source File: GoogleMapShapeConverterUtils.java    From geopackage-android-map with MIT License 6 votes vote down vote up
/**
 * Test the PolyhedralSurface conversion
 * 
 * @param converter
 * @param polyhedralSurface
 */
private static void convertMultiPolygon(GoogleMapShapeConverter converter,
		PolyhedralSurface polyhedralSurface) {

	MultiPolygonOptions mapPolygons = converter
			.toPolygons(polyhedralSurface);
	TestCase.assertNotNull(mapPolygons);
	TestCase.assertFalse(mapPolygons.getPolygonOptions().isEmpty());

	List<Polygon> polygons = polyhedralSurface.getPolygons();
	comparePolygonsAndMapPolygons(converter, polygons, mapPolygons.getPolygonOptions());

	PolyhedralSurface polyhedralSurface2 = converter
			.toPolyhedralSurfaceWithOptions(mapPolygons);
	comparePolygons(polygons, polyhedralSurface.getPolygons());
}
 
Example 3
Source File: AttributesUtils.java    From geopackage-android with MIT License 5 votes vote down vote up
/**
 * Test delete
 *
 * @param geoPackage GeoPackage
 * @throws SQLException upon error
 */
public static void testDelete(GeoPackage geoPackage) throws SQLException {

    List<String> tables = geoPackage.getAttributesTables();

    if (!tables.isEmpty()) {

        for (String tableName : tables) {

            AttributesDao dao = geoPackage.getAttributesDao(tableName);
            TestCase.assertNotNull(dao);

            AttributesCursor cursor = dao.queryForAll();
            int count = cursor.getCount();
            if (count > 0) {

                // Choose random attribute
                int random = (int) (Math.random() * count);
                cursor.moveToPosition(random);

                AttributesRow attributesRow = cursor.getRow();
                cursor.close();

                // Delete row
                TestCase.assertEquals(1, dao.delete(attributesRow));

                // Verify deleted
                AttributesRow queryAttributesRow = dao
                        .queryForIdRow(attributesRow.getId());
                TestCase.assertNull(queryAttributesRow);
                cursor = dao.queryForAll();
                TestCase.assertEquals(count - 1, cursor.getCount());
                cursor.close();
            }
            cursor.close();
        }
    }
}
 
Example 4
Source File: CCServicesTest.java    From scipio-erp with Apache License 2.0 5 votes vote down vote up
public void testCredit() throws Exception {
    Debug.logInfo("=====[testCCredit] starting....", module);
    try {
        Map<String, Object> serviceMap = UtilMisc.<String, Object>toMap("paymentConfig", configFile,
                "orderId", orderId,
                "creditAmount", creditAmount,
                "billToEmail", emailAddr,
                "creditCard", creditCard,
                "creditAmount", new BigDecimal("200.00"));
        // run the service
        Map<String, Object> result = dispatcher.runSync("clearCommerceCCCredit", serviceMap);

        // verify the results
        String responseMessage = (String) result.get(ModelService.RESPONSE_MESSAGE);
        Debug.logInfo("[testCCCredit] responseMessage: " + responseMessage, module);
        TestCase.assertEquals("Service result is success", ModelService.RESPOND_SUCCESS, responseMessage);
        TestCase.assertNotNull("Service returned null for parameter creditResult.", result.get("creditResult"));

        if ((Boolean.FALSE).equals(result.get("creditResult"))) { // returnCode ok?
            Debug.logInfo("[testCCCredit] Error Messages from ClearCommerce: " + result.get("internalRespMsgs"), module);
            TestCase.fail("Returned messages:" + result.get("internalRespMsgs"));
        }
    } catch (GenericServiceException ex) {
        TestCase.fail(ex.getMessage());
    }

}
 
Example 5
Source File: NBTTestCase.java    From NBT with MIT License 5 votes vote down vote up
protected File copyResourceToTmp(String resource) {
	URL resFileURL = getClass().getClassLoader().getResource(resource);
	TestCase.assertNotNull(resFileURL);
	File resFile = new File(resFileURL.getFile());
	File tmpFile = getNewTmpFile(resource);
	assertThrowsNoException(() -> Files.copy(resFile.toPath(), tmpFile.toPath()));
	return tmpFile;
}
 
Example 6
Source File: IUserServiceTest.java    From spring-boot-seed with MIT License 5 votes vote down vote up
@Test
    public void queryByIdOrName() {
        User user = userService.queryByIdOrName(1L, null);
//        User user = userService.queryByIdOrName(null, "admin");
        log.info("==========================================================================");
        log.info("查询结果 ==> {}", user);
        log.info("==========================================================================");
        TestCase.assertNotNull(user);
    }
 
Example 7
Source File: FeatureStylesUtils.java    From geopackage-android with MIT License 5 votes vote down vote up
private static void validateRowIcons(FeatureTableStyles featureTableStyles,
                                     FeatureRow featureRow, GeometryType geometryType,
                                     IconRow tableIconDefault,
                                     Map<GeometryType, IconRow> geometryTypeTableIcons,
                                     Map<Long, Map<GeometryType, IconRow>> featureResultsIcons) {

    IconRow iconRow = null;
    if (geometryType == null) {
        iconRow = featureTableStyles.getIcon(featureRow);
        geometryType = featureRow.getGeometryType();
    } else {
        iconRow = featureTableStyles.getIcon(featureRow, geometryType);
    }

    IconRow expectedIconRow = getExpectedRowIcon(featureRow, geometryType,
            tableIconDefault, geometryTypeTableIcons, featureResultsIcons);

    if (expectedIconRow != null) {
        TestCase.assertEquals(expectedIconRow.getId(), iconRow.getId());
        TestCase.assertNotNull(iconRow.getTable());
        TestCase.assertTrue(iconRow.getId() >= 0);
        iconRow.getName();
        iconRow.getDescription();
        iconRow.getWidth();
        iconRow.getHeight();
        iconRow.getAnchorU();
        iconRow.getAnchorV();
    } else {
        TestCase.assertNull(iconRow);
    }

}
 
Example 8
Source File: TestTransformJSONResource.java    From localization_nifi with Apache License 2.0 5 votes vote down vote up
@Test
public void testValidateWithValidSpec() {
    JoltSpecificationDTO joltSpecificationDTO = new JoltSpecificationDTO("jolt-transform-remove","{\"rating\": {\"quality\": \"\"} }");
    ValidationDTO validation  = client().resource(getBaseURI()).path("/standard/transformjson/validate").post(ValidationDTO.class, joltSpecificationDTO);
    TestCase.assertNotNull(validation);
    assertTrue(validation.isValid());
}
 
Example 9
Source File: TestTransformJSONResource.java    From localization_nifi with Apache License 2.0 5 votes vote down vote up
@Test
public void testValidateWithValidEmptySpec() {
    JoltSpecificationDTO joltSpecificationDTO = new JoltSpecificationDTO("jolt-transform-sort","");
    ValidationDTO validation  = client().resource(getBaseURI()).path("/standard/transformjson/validate").post(ValidationDTO.class, joltSpecificationDTO);
    TestCase.assertNotNull(validation);
    assertTrue(validation.isValid());
}
 
Example 10
Source File: RelatedSimpleAttributesUtils.java    From geopackage-java with MIT License 5 votes vote down vote up
/**
 * Validate contents
 * 
 * @param simpleAttributesTable
 *            simple attributes table
 * @param contents
 *            contents
 */
private static void validateContents(
		SimpleAttributesTable simpleAttributesTable, Contents contents) {
	TestCase.assertNotNull(contents);
	TestCase.assertNotNull(contents.getDataType());
	TestCase.assertEquals(
			SimpleAttributesTable.RELATION_TYPE.getDataType(), contents
					.getDataType().getName());
	TestCase.assertEquals(
			SimpleAttributesTable.RELATION_TYPE.getDataType(),
			contents.getDataTypeString());
	TestCase.assertEquals(simpleAttributesTable.getTableName(),
			contents.getTableName());
	TestCase.assertNotNull(contents.getLastChange());
}
 
Example 11
Source File: TestTransformJSONResource.java    From localization_nifi with Apache License 2.0 5 votes vote down vote up
@Test
public void testValidateWithValidNullSpec() {
    JoltSpecificationDTO joltSpecificationDTO = new JoltSpecificationDTO("jolt-transform-sort",null);
    ValidationDTO validation  = client().resource(getBaseURI()).path("/standard/transformjson/validate").post(ValidationDTO.class, joltSpecificationDTO);
    TestCase.assertNotNull(validation);
    assertTrue(validation.isValid());
}
 
Example 12
Source File: PortUtilityTest.java    From datasync with MIT License 4 votes vote down vote up
@Test
public void testSchemaAdaptation() {
    // set up original dataset schema
    String groupingKey = "grouping_aggregate";
    Dataset schema = new Dataset();

    Column colNoFormatting = new Column();
    colNoFormatting.setFieldName("col_without_formatting");

    Column colIgnorableFormatting = new Column();
    colIgnorableFormatting.setFieldName("col_with_ignorable_formatting");
    Map<String, String> ignorableFormatting = new HashMap<String,String>();
    ignorableFormatting.put("drill_down", "true");
    colIgnorableFormatting.setFormat(ignorableFormatting);

    Column colAggregatedFormatting = new Column();
    colAggregatedFormatting.setFieldName("col_with_aggregated_formatting");
    Map<String, String> aggregateFormatting = new HashMap<String,String>();
    aggregateFormatting.put(groupingKey, "count");
    colAggregatedFormatting.setFormat(aggregateFormatting);

    List<Column> columns = new ArrayList<Column>();
    columns.add(colNoFormatting);
    columns.add(colIgnorableFormatting);
    columns.add(colAggregatedFormatting);
    schema.setColumns(columns);

    // edit schema
    PortUtility.adaptSchemaForAggregates(schema);

    // test that edits are as expected
    List<Column> editedColumns = schema.getColumns();
    Column col1 = editedColumns.get(0);
    Column col2 = editedColumns.get(1);
    Column col3 = editedColumns.get(2);

    TestCase.assertNotNull(col1);
    TestCase.assertNotNull(col2);
    TestCase.assertNotNull(col3);

    // columns without formatting should be left alone
    TestCase.assertEquals(colNoFormatting, col1);

    // columns with ignorable formatting should be left alone
    TestCase.assertEquals(colIgnorableFormatting, col2);

    // columns with aggregation info in the formatting should have the aggregation info removed
    // and prepended to the field name:
    TestCase.assertFalse(col3.getFormat().containsKey(groupingKey));
    TestCase.assertEquals("count_col_with_aggregated_formatting", col3.getFieldName());
}
 
Example 13
Source File: CallbackForTest.java    From tracing-framework with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
public void expectTuples(List<ResultsTuple> tuples) throws InterruptedException {
    QueryResults results = awaitResults();
    TestCase.assertNotNull(results);
    TestCase.assertEquals(0, results.getGroupCount());
    TestCase.assertEquals(tuples, results.getTupleList());
}
 
Example 14
Source File: CoverageDataTestUtils.java    From geopackage-android with MIT License 4 votes vote down vote up
/**
 * Test the pixel encoding location
 *
 * @param geoPackage GeoPackage
 * @param allowNulls allow nulls
 * @throws Exception
 */
public static void testPixelEncoding(GeoPackage geoPackage,
                                     boolean allowNulls) throws Exception {

    List<String> coverageDataTables = CoverageData.getTables(geoPackage);
    TestCase.assertFalse(coverageDataTables.isEmpty());

    TileMatrixSetDao tileMatrixSetDao = geoPackage.getTileMatrixSetDao();
    TestCase.assertTrue(tileMatrixSetDao.isTableExists());
    TileMatrixDao tileMatrixDao = geoPackage.getTileMatrixDao();
    TestCase.assertTrue(tileMatrixDao.isTableExists());

    for (String coverageTable : coverageDataTables) {

        TileMatrixSet tileMatrixSet = tileMatrixSetDao
                .queryForId(coverageTable);

        TileDao tileDao = geoPackage.getTileDao(tileMatrixSet);
        CoverageData<?> coverageData = CoverageData.getCoverageData(
                geoPackage, tileDao);
        GriddedCoverage griddedCoverage = coverageData.getGriddedCoverage();
        GriddedCoverageEncodingType encoding = griddedCoverage
                .getGridCellEncodingType();

        TileCursor tileCursor = tileDao.queryForTile(tileDao
                .getMaxZoom());
        TestCase.assertNotNull(tileCursor);
        try {
            TestCase.assertTrue(tileCursor.getCount() > 0);
            while (tileCursor.moveToNext()) {
                TileRow tileRow = tileCursor.getRow();

                TileMatrix tileMatrix = tileDao.getTileMatrix(tileRow
                        .getZoomLevel());
                TestCase.assertNotNull(tileMatrix);

                GriddedTile griddedTile = coverageData.getGriddedTile(tileRow
                        .getId());
                TestCase.assertNotNull(griddedTile);

                byte[] tileData = tileRow.getTileData();
                TestCase.assertNotNull(tileData);

                BoundingBox boundingBox = TileBoundingBoxUtils.getBoundingBox(
                        tileMatrixSet.getBoundingBox(), tileMatrix,
                        tileRow.getTileColumn(), tileRow.getTileRow());

                int tileHeight = (int) tileMatrix.getTileHeight();
                int tileWidth = (int) tileMatrix.getTileWidth();

                int heightChunk = Math.max(tileHeight / 10, 1);
                int widthChunk = Math.max(tileWidth / 10, 1);

                for (int y = 0; y < tileHeight; y = Math.min(y + heightChunk,
                        y == tileHeight - 1 ? tileHeight : tileHeight - 1)) {
                    for (int x = 0; x < tileWidth; x = Math.min(x + widthChunk,
                            x == tileWidth - 1 ? tileWidth : tileWidth - 1)) {

                        Double pixelValue = coverageData.getValue(griddedTile,
                                tileData, x, y);
                        double pixelLongitude = boundingBox.getMinLongitude()
                                + (x * tileMatrix.getPixelXSize());
                        double pixelLatitude = boundingBox.getMaxLatitude()
                                - (y * tileMatrix.getPixelYSize());
                        switch (encoding) {
                            case CENTER:
                            case AREA:
                                pixelLongitude += (tileMatrix.getPixelXSize() / 2.0);
                                pixelLatitude -= (tileMatrix.getPixelYSize() / 2.0);
                                break;
                            case CORNER:
                                pixelLatitude -= tileMatrix.getPixelYSize();
                                break;
                        }
                        Double value = coverageData.getValue(pixelLatitude,
                                pixelLongitude);

                        if (!allowNulls || pixelValue != null) {
                            TestCase.assertEquals("x: " + x + ", y: " + y
                                            + ", encoding: " + encoding, pixelValue,
                                    value);
                        }
                    }
                }

                break;
            }
        } finally {
            tileCursor.close();
        }
    }

}
 
Example 15
Source File: GeoPackageGeometryDataUtils.java    From geopackage-android with MIT License 4 votes vote down vote up
/**
 * Test transforming geometries between projections
 *
 * @param geoPackage
 * @throws SQLException
 * @throws IOException
 */
public static void testGeometryProjectionTransform(GeoPackage geoPackage)
        throws SQLException, IOException {

    GeometryColumnsDao geometryColumnsDao = geoPackage
            .getGeometryColumnsDao();

    if (geometryColumnsDao.isTableExists()) {
        List<GeometryColumns> results = geometryColumnsDao.queryForAll();

        for (GeometryColumns geometryColumns : results) {

            FeatureDao dao = geoPackage.getFeatureDao(geometryColumns);
            TestCase.assertNotNull(dao);

            FeatureCursor cursor = dao.queryForAll();

            while (cursor.moveToNext()) {

                GeoPackageGeometryData geometryData = cursor.getGeometry();
                if (geometryData != null) {

                    Geometry geometry = geometryData.getGeometry();

                    if (geometry != null) {

                        SpatialReferenceSystemDao srsDao = geoPackage
                                .getSpatialReferenceSystemDao();
                        long srsId = geometryData.getSrsId();
                        SpatialReferenceSystem srs = srsDao
                                .queryForId(srsId);

                        long epsg = srs.getOrganizationCoordsysId();
                        Projection projection = srs.getProjection();
                        long toEpsg = -1;
                        if (epsg == ProjectionConstants.EPSG_WORLD_GEODETIC_SYSTEM) {
                            toEpsg = ProjectionConstants.EPSG_WEB_MERCATOR;
                        } else {
                            toEpsg = ProjectionConstants.EPSG_WORLD_GEODETIC_SYSTEM;
                        }
                        ProjectionTransform transformTo = projection
                                .getTransformation(toEpsg);
                        ProjectionTransform transformFrom = srs.getTransformation(transformTo
                                .getToProjection());

                        byte[] bytes = geometryData.getWkbBytes();

                        Geometry projectedGeometry = transformTo
                                .transform(geometry);
                        GeoPackageGeometryData projectedGeometryData = new GeoPackageGeometryData(
                                -1);
                        projectedGeometryData
                                .setGeometry(projectedGeometry);
                        projectedGeometryData.toBytes();
                        byte[] projectedBytes = projectedGeometryData
                                .getWkbBytes();

                        if (epsg > 0) {
                            TestCase.assertFalse(equalByteArrays(bytes,
                                    projectedBytes));
                        }

                        Geometry restoredGeometry = transformFrom
                                .transform(projectedGeometry);

                        compareGeometries(geometry, restoredGeometry, .001);
                    }
                }

            }
            cursor.close();
        }
    }
}
 
Example 16
Source File: UserServiceIT.java    From dubbo-samples with Apache License 2.0 4 votes vote down vote up
@Test
public void test() {
    UserInfo userInfo = consumer.insertUserInfo("dubbo");
    TestCase.assertEquals("dubbo", userInfo.getName());
    TestCase.assertNotNull(userInfo.getUuid());
}
 
Example 17
Source File: GeoPackageTestUtils.java    From geopackage-java with MIT License 4 votes vote down vote up
/**
 * Validate feature table with metadata
 * 
 * @param geoPackage
 * @throws SQLException
 */
private static void validateFeatureTableWithMetadata(GeoPackage geoPackage,
		GeometryColumns geometryColumns, String idColumn,
		List<FeatureColumn> additionalColumns) throws SQLException {

	GeometryColumnsDao dao = geoPackage.getGeometryColumnsDao();

	GeometryColumns queryGeometryColumns = dao
			.queryForId(geometryColumns.getId());
	TestCase.assertNotNull(queryGeometryColumns);

	TestCase.assertEquals(geometryColumns.getTableName(),
			queryGeometryColumns.getTableName());
	TestCase.assertEquals(geometryColumns.getColumnName(),
			queryGeometryColumns.getColumnName());
	TestCase.assertEquals(GeometryType.POINT,
			queryGeometryColumns.getGeometryType());
	TestCase.assertEquals(geometryColumns.getZ(),
			queryGeometryColumns.getZ());
	TestCase.assertEquals(geometryColumns.getM(),
			queryGeometryColumns.getM());

	FeatureDao featureDao = geoPackage
			.getFeatureDao(geometryColumns.getTableName());
	FeatureRow featureRow = featureDao.newRow();

	TestCase.assertEquals(
			2 + (additionalColumns != null ? additionalColumns.size() : 0),
			featureRow.columnCount());
	if (idColumn == null) {
		idColumn = "id";
	}
	TestCase.assertEquals(idColumn, featureRow.getColumnName(0));
	TestCase.assertEquals(geometryColumns.getColumnName(),
			featureRow.getColumnName(1));

	if (additionalColumns != null) {
		TestCase.assertEquals("test_text", featureRow.getColumnName(2));
		TestCase.assertEquals("test_real", featureRow.getColumnName(3));
		TestCase.assertEquals("test_boolean", featureRow.getColumnName(4));
		TestCase.assertEquals("test_blob", featureRow.getColumnName(5));
		TestCase.assertEquals("test_integer", featureRow.getColumnName(6));
		TestCase.assertEquals("test_text_limited",
				featureRow.getColumnName(7));
		TestCase.assertEquals("test_blob_limited",
				featureRow.getColumnName(8));
	}
}
 
Example 18
Source File: UrlTileGeneratorUtils.java    From geopackage-java with MIT License 4 votes vote down vote up
/**
 * Test generating tiles
 * 
 * @param tileGenerator
 * @throws SQLException
 * @throws IOException
 */
private static void testGenerateTiles(TileGenerator tileGenerator)
		throws SQLException, IOException {

	GeoPackage geoPackage = tileGenerator.getGeoPackage();
	String tableName = tileGenerator.getTableName();
	int minZoom = tileGenerator.getMinZoom();
	int maxZoom = tileGenerator.getMaxZoom();
	BoundingBox webMercatorBoundingBox = tileGenerator.getBoundingBox();

	TestGeoPackageProgress progress = new TestGeoPackageProgress();
	tileGenerator.setProgress(progress);

	int count = tileGenerator.generateTiles();

	long expected = expectedTiles(webMercatorBoundingBox, minZoom, maxZoom);
	TestCase.assertEquals(expected, count);
	TestCase.assertEquals(expected, progress.getProgress());

	TileDao tileDao = geoPackage.getTileDao(tableName);
	TestCase.assertEquals(expected, tileDao.count());
	TestCase.assertEquals(minZoom, tileDao.getMinZoom());
	TestCase.assertEquals(maxZoom, tileDao.getMaxZoom());

	BoundingBox tileMatrixSetBoundingBox = tileDao.getBoundingBox();

	for (int zoom = minZoom; zoom <= maxZoom; zoom++) {
		TileGrid expectedTileGrid = TileBoundingBoxUtils.getTileGrid(
				webMercatorBoundingBox, zoom);
		BoundingBox expectedBoundingBox = TileBoundingBoxUtils
				.getWebMercatorBoundingBox(expectedTileGrid, zoom);
		BoundingBox zoomBoundingBox = tileDao.getBoundingBox(zoom);
		TestCase.assertEquals(expectedBoundingBox.getMinLongitude(),
				zoomBoundingBox.getMinLongitude(), .000001);
		TestCase.assertEquals(expectedBoundingBox.getMaxLongitude(),
				zoomBoundingBox.getMaxLongitude(), .000001);
		TestCase.assertEquals(expectedBoundingBox.getMinLatitude(),
				zoomBoundingBox.getMinLatitude(), .000001);
		TestCase.assertEquals(expectedBoundingBox.getMaxLatitude(),
				zoomBoundingBox.getMaxLatitude(), .000001);
		long expectedZoomTiles = expectedTiles(webMercatorBoundingBox, zoom);
		TestCase.assertEquals(expectedZoomTiles, tileDao.count(zoom));

		TileMatrix tileMatrix = tileDao.getTileMatrix(zoom);

		TileGrid tileGrid = TileBoundingBoxUtils.getTileGrid(
				tileMatrixSetBoundingBox, tileMatrix.getMatrixWidth(),
				tileMatrix.getMatrixHeight(), zoomBoundingBox);

		TestCase.assertTrue(tileGrid.getMinX() >= 0);
		TestCase.assertTrue(tileGrid.getMaxX() < tileMatrix
				.getMatrixWidth());
		TestCase.assertTrue(tileGrid.getMinY() >= 0);
		TestCase.assertTrue(tileGrid.getMaxY() < tileMatrix
				.getMatrixHeight());

		TileResultSet resultSet = tileDao.queryForTile(zoom);
		TestCase.assertEquals(expectedZoomTiles, resultSet.getCount());
		int resultCount = 0;
		while (resultSet.moveToNext()) {
			TileRow tileRow = resultSet.getRow();
			resultCount++;
			byte[] tileData = tileRow.getTileData();
			TestCase.assertNotNull(tileData);
			BufferedImage image = tileRow.getTileDataImage();
			TestCase.assertNotNull(image);
			TestCase.assertEquals(tileMatrix.getTileWidth(),
					image.getWidth());
			TestCase.assertEquals(tileMatrix.getTileHeight(),
					image.getHeight());
		}
		TestCase.assertEquals(expectedZoomTiles, resultCount);
	}

}
 
Example 19
Source File: StyleUtilsTest.java    From geopackage-android-map with MIT License 4 votes vote down vote up
private void testSetIcon(float density, int imageWidth, int imageHeight, Double iconWidth, Double iconHeight) throws Exception {

        Bitmap bitmap = Bitmap.createBitmap(imageWidth, imageHeight, Bitmap.Config.ARGB_8888);
        byte[] bytes = BitmapConverter.toBytes(bitmap, Bitmap.CompressFormat.PNG);

        IconRow icon = new IconRow();
        icon.setData(bytes);
        icon.setWidth(iconWidth);
        icon.setHeight(iconHeight);

        double styleWidth;
        double styleHeight;

        if (iconWidth == null && iconHeight == null) {
            styleWidth = imageWidth;
            styleHeight = imageHeight;
        } else if (iconWidth != null && iconHeight != null) {
            styleWidth = iconWidth;
            styleHeight = iconHeight;
        } else if (iconWidth != null) {
            styleWidth = iconWidth;
            styleHeight = (iconWidth / imageWidth) * imageHeight;
        } else {
            styleHeight = iconHeight;
            styleWidth = (iconHeight / imageHeight) * imageWidth;
        }

        Bitmap iconImage = StyleUtils.createIcon(icon, density);
        TestCase.assertNotNull(iconImage);

        double expectedWidth = density * styleWidth;
        double expectedHeight = density * styleHeight;

        int lowerWidth = (int) Math.floor(expectedWidth - 0.5);
        int upperWidth = (int) Math.ceil(expectedWidth + 0.5);
        int lowerHeight = (int) Math.floor(expectedHeight - 0.5);
        int upperHeight = (int) Math.ceil(expectedHeight + 0.5);

        TestCase.assertTrue(iconImage.getWidth() + " not between " + lowerWidth + " and " + upperWidth,
                iconImage.getWidth() >= lowerWidth
                        && iconImage.getWidth() <= upperWidth);
        TestCase.assertTrue(iconImage.getHeight() + " not between " + lowerHeight + " and " + upperHeight,
                iconImage.getHeight() >= lowerHeight
                        && iconImage.getHeight() <= upperHeight);

    }
 
Example 20
Source File: GeoPackageTestUtils.java    From geopackage-android with MIT License 4 votes vote down vote up
/**
 * Test deleting tables by name
 *
 * @param geoPackage
 * @throws SQLException
 */
public static void testDeleteTables(GeoPackage geoPackage)
        throws SQLException {

    GeometryColumnsDao geometryColumnsDao = geoPackage
            .getGeometryColumnsDao();
    TileMatrixSetDao tileMatrixSetDao = geoPackage.getTileMatrixSetDao();
    ContentsDao contentsDao = geoPackage.getContentsDao();

    TestCase.assertTrue(geometryColumnsDao.isTableExists()
            || tileMatrixSetDao.isTableExists());

    geoPackage.foreignKeys(false);

    if (geometryColumnsDao.isTableExists()) {

        TestCase.assertEquals(geoPackage.getFeatureTables().size(),
                geometryColumnsDao.countOf());
        for (String featureTable : geoPackage.getFeatureTables()) {
            TestCase.assertTrue(geoPackage.isTable(featureTable));
            TestCase.assertNotNull(contentsDao.queryForId(featureTable));
            geoPackage.deleteTable(featureTable);
            TestCase.assertFalse(geoPackage.isTable(featureTable));
            TestCase.assertNull(contentsDao.queryForId(featureTable));
        }
        TestCase.assertEquals(0, geometryColumnsDao.countOf());

        geoPackage.dropTable(GeometryColumns.TABLE_NAME);

        TestCase.assertFalse(geometryColumnsDao.isTableExists());
    }

    if (tileMatrixSetDao.isTableExists()) {
        TileMatrixDao tileMatrixDao = geoPackage.getTileMatrixDao();

        TestCase.assertTrue(tileMatrixSetDao.isTableExists());
        TestCase.assertTrue(tileMatrixDao.isTableExists());

        TestCase.assertEquals(geoPackage.getTables(ContentsDataType.TILES).size() + geoPackage.getTables(ContentsDataType.GRIDDED_COVERAGE).size(),
                tileMatrixSetDao.countOf());
        for (String tileTable : geoPackage.getTileTables()) {
            TestCase.assertTrue(geoPackage.isTable(tileTable));
            TestCase.assertNotNull(contentsDao.queryForId(tileTable));
            geoPackage.deleteTable(tileTable);
            TestCase.assertFalse(geoPackage.isTable(tileTable));
            TestCase.assertNull(contentsDao.queryForId(tileTable));
        }
        TestCase.assertEquals(geoPackage.getTables(ContentsDataType.GRIDDED_COVERAGE).size(), tileMatrixSetDao.countOf());

        geoPackage.dropTable(TileMatrix.TABLE_NAME);
        geoPackage.dropTable(TileMatrixSet.TABLE_NAME);

        TestCase.assertFalse(tileMatrixSetDao.isTableExists());
        TestCase.assertFalse(tileMatrixDao.isTableExists());
    }

    for (String attributeTable : geoPackage.getAttributesTables()) {

        TestCase.assertTrue(geoPackage.isTable(attributeTable));
        TestCase.assertNotNull(contentsDao.queryForId(attributeTable));
        geoPackage.deleteTable(attributeTable);
        TestCase.assertFalse(geoPackage.isTable(attributeTable));
        TestCase.assertNull(contentsDao.queryForId(attributeTable));

    }

}