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

The following examples show how to use junit.framework.TestCase#assertNull() . 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: GeoPackageGeometryDataUtils.java    From geopackage-android with MIT License 6 votes vote down vote up
/**
 * Compare two geometry envelopes and verify they are equal
 *
 * @param expected
 * @param actual
 */
private static void compareEnvelopes(GeometryEnvelope expected,
                                     GeometryEnvelope actual) {

    if (expected == null) {
        TestCase.assertNull(actual);
    } else {
        TestCase.assertNotNull(actual);

        TestCase.assertEquals(GeoPackageGeometryData.getIndicator(expected),
                GeoPackageGeometryData.getIndicator(actual));
        TestCase.assertEquals(expected.getMinX(), actual.getMinX());
        TestCase.assertEquals(expected.getMaxX(), actual.getMaxX());
        TestCase.assertEquals(expected.getMinY(), actual.getMinY());
        TestCase.assertEquals(expected.getMaxY(), actual.getMaxY());
        TestCase.assertEquals(expected.hasZ(), actual.hasZ());
        TestCase.assertEquals(expected.getMinZ(), actual.getMinZ());
        TestCase.assertEquals(expected.getMaxZ(), actual.getMaxZ());
        TestCase.assertEquals(expected.hasM(), actual.hasM());
        TestCase.assertEquals(expected.getMinM(), actual.getMinM());
        TestCase.assertEquals(expected.getMaxM(), actual.getMaxM());
    }

}
 
Example 2
Source File: ConccSemanticsTests.java    From Concurnas with MIT License 6 votes vote down vote up
@Test
public void includeFriendsFromDirManyFriends() throws IOException {
	ConccTestMockFileLoader mockFL = new ConccTestMockFileLoader();
	ConccTestMockFileWriter mockWriter = new ConccTestMockFileWriter(mockFL);

	Path workDir = mockFL.fs.getPath("/work/com/thing/");
	Files.createDirectories(workDir);
	Files.createFile(workDir.resolve("MyFirstClass.conc"));
	Files.createFile(workDir.resolve("MyFirstClass2.conc"));
	
	Concc concc = new Concc("/work/[com/thing/MyFirstClass.conc com/thing/MyFirstClass2.conc]", mockFL, mockWriter);
	
	ValidationErrorsAndValidObject validAndVO = concc.validateConccInstance(concc.getConccInstance());
	//no filtering at this point
	TestCase.assertNull(validAndVO.validationErrs);
	String expect = "/work/com/thing/MyFirstClass.conc[com.thing true] /work/com/thing/MyFirstClass2.conc[com.thing false] /work/com/thing/MyFirstClass2.conc[com.thing true] /work/com/thing/MyFirstClass.conc[com.thing false]";
	TestCase.assertEquals(expect, validAndVO.validconcObject.toString());
}
 
Example 3
Source File: GeoPackageGeometryDataUtils.java    From geopackage-java with MIT License 6 votes vote down vote up
/**
 * Compare two geometry envelopes and verify they are equal
 * 
 * @param expected
 * @param actual
 */
private static void compareEnvelopes(GeometryEnvelope expected,
		GeometryEnvelope actual) {

	if (expected == null) {
		TestCase.assertNull(actual);
	} else {
		TestCase.assertNotNull(actual);

		TestCase.assertEquals(
				GeoPackageGeometryData.getIndicator(expected),
				GeoPackageGeometryData.getIndicator(actual));
		TestCase.assertEquals(expected.getMinX(), actual.getMinX());
		TestCase.assertEquals(expected.getMaxX(), actual.getMaxX());
		TestCase.assertEquals(expected.getMinY(), actual.getMinY());
		TestCase.assertEquals(expected.getMaxY(), actual.getMaxY());
		TestCase.assertEquals(expected.hasZ(), actual.hasZ());
		TestCase.assertEquals(expected.getMinZ(), actual.getMinZ());
		TestCase.assertEquals(expected.getMaxZ(), actual.getMaxZ());
		TestCase.assertEquals(expected.hasM(), actual.hasM());
		TestCase.assertEquals(expected.getMinM(), actual.getMinM());
		TestCase.assertEquals(expected.getMaxM(), actual.getMaxM());
	}

}
 
Example 4
Source File: TestQueueMuxBatchmgr.java    From oodt with Apache License 2.0 6 votes vote down vote up
public void testGetExecNode() {
    try {
        ResourceNode node1 = new ResourceNode();
        ResourceNode node2 = new ResourceNode();
        node1.setId("Node1-ID");
        node2.setId("Node2-ID");           
        JobSpec spec1 = this.getSpecFromQueue("queue-1");
        queue.executeRemotely(spec1, node1);

        JobSpec spec2 = this.getSpecFromQueue("queue-2");
        queue.executeRemotely(spec2, node2);
        //Make that the execution node is same
        TestCase.assertEquals(node1.getNodeId(),queue.getExecutionNode(spec1.getJob().getId()));
        TestCase.assertEquals(node2.getNodeId(),queue.getExecutionNode(spec2.getJob().getId()));
        //Returns null, if bad-queue
        TestCase.assertNull(queue.getExecutionNode(this.getSpecFromQueue("queue-3").getJob().getId()));
    } catch (JobExecutionException e) {
        TestCase.fail("Unexpected Exception: "+e.getMessage());
    }
}
 
Example 5
Source File: AbstractInterfaceConfigTest.java    From dubbo-2.6.5 with Apache License 2.0 5 votes vote down vote up
@Test
public void testStub() throws Exception {
    InterfaceConfig interfaceConfig = new InterfaceConfig();
    interfaceConfig.setStub((Boolean) null);
    TestCase.assertNull(interfaceConfig.getStub());
    interfaceConfig.setStub(true);
    TestCase.assertEquals("true", interfaceConfig.getStub());
    interfaceConfig.setStub("GreetingMock");
    TestCase.assertEquals("GreetingMock", interfaceConfig.getStub());
}
 
Example 6
Source File: FeatureUtils.java    From geopackage-java 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 {

	GeometryColumnsDao geometryColumnsDao = geoPackage
			.getGeometryColumnsDao();

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

		for (GeometryColumns geometryColumns : results) {

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

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

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

				FeatureRow featureRow = cursor.getRow();
				cursor.close();

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

				// Verify deleted
				FeatureRow queryFeatureRow = dao.queryForIdRow(featureRow
						.getId());
				TestCase.assertNull(queryFeatureRow);
				cursor = dao.queryForAll();
				TestCase.assertEquals(count - 1, cursor.getCount());
				cursor.close();
			}
			cursor.close();
		}
	}
}
 
Example 7
Source File: ConcSemanticsTests.java    From Concurnas with MIT License 5 votes vote down vote up
@Test
public void simpleValidClassRequestImplicitClass() throws IOException {
	String code = "def main() void => System.err.println('hey')";
	
	Pair<ConccTestMockFileLoader, CLProviderToIMM> mAndP = createMFL("/work", "/work/hg", "MyFirstClass", code);
	Conc concc = new Conc("/work/hg/MyFirstClass", mAndP.getA(), mAndP.getB());//implicit class ref
	
	TestCase.assertNull(concc.validateConcInstance(concc.getConcInstance()).validationErrs);
}
 
Example 8
Source File: TileUtils.java    From geopackage-java 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 {

	TileMatrixSetDao tileMatrixSetDao = geoPackage.getTileMatrixSetDao();

	if (tileMatrixSetDao.isTableExists()) {
		List<TileMatrixSet> results = tileMatrixSetDao.queryForAll();

		for (TileMatrixSet tileMatrixSet : results) {

			TileDao dao = geoPackage.getTileDao(tileMatrixSet);
			TestCase.assertNotNull(dao);

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

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

				TileRow tileRow = cursor.getRow();
				cursor.close();

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

				// Verify deleted
				TileRow queryTileRow = dao.queryForIdRow(tileRow.getId());
				TestCase.assertNull(queryTileRow);
				cursor = dao.queryForAll();
				TestCase.assertEquals(count - 1, cursor.getCount());
				cursor.close();
			}
			cursor.close();
		}

	}
}
 
Example 9
Source File: AttributesUtils.java    From geopackage-java 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);

			AttributesResultSet 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 10
Source File: RedisClientTemplateTest.java    From spring-boot-seed with MIT License 5 votes vote down vote up
@Test
public void expireAt() {
    //TODO 单元测试未通过
    redisClientTemplate.set("test.key", "expireAt key");
    redisClientTemplate.expireAt("test.key", System.currentTimeMillis() + 2000);
    TestCase.assertEquals("expireAt key", redisClientTemplate.get("test.key"));
    try {
        Thread.sleep(50000);
        TestCase.assertNull(redisClientTemplate.get("test.key"));
        log.info("============= redis expireAt success ==============");
    } catch (InterruptedException e) {
        e.printStackTrace();
        log.info("============= redis expireAt error ==============");
    }
}
 
Example 11
Source File: TestUtils.java    From geopackage-android with MIT License 4 votes vote down vote up
/**
 * Validate the integrity and keys of the GeoPackage
 *
 * @param geoPackage
 */
public static void validateGeoPackage(GeoPackage geoPackage) {
    TestCase.assertNull(geoPackage.foreignKeyCheck());
    TestCase.assertNull(geoPackage.integrityCheck());
    TestCase.assertNull(geoPackage.quickCheck());
}
 
Example 12
Source File: MetadataReferenceUtils.java    From geopackage-java with MIT License 4 votes vote down vote up
/**
 * Test create
 * 
 * @param geoPackage
 * @throws SQLException
 */
public static void testCreate(GeoPackage geoPackage) throws SQLException {

	MetadataReferenceDao dao = geoPackage.getMetadataReferenceDao();
	MetadataDao metadataDao = geoPackage.getMetadataDao();

	if (dao.isTableExists()) {
		// Get current count
		long count = dao.countOf();

		long fileId = 5555;
		long parentId = 5556;

		// Create new metadata
		Metadata metadata = new Metadata();
		metadata.setId(fileId);
		metadata.setMetadataScope(MetadataScopeType.FEATURE);
		metadata.setStandardUri("https://www.nga.mil");
		metadata.setMimeType("text/xml");
		metadata.setMetadata("Create metadata text");
		metadataDao.create(metadata);

		Metadata metadata2 = new Metadata();
		metadata2.setId(parentId);
		metadata2.setMetadataScope(MetadataScopeType.FEATURE_TYPE);
		metadata2.setStandardUri("https://www.nga.mil");
		metadata2.setMimeType("text/xml");
		metadata2.setMetadata("Create metadata text 2");
		metadataDao.create(metadata2);

		ReferenceScopeType scopeType = ReferenceScopeType.ROW;
		String tableName = "CREATE_TABLE_NAME";
		long rowIdValue = 50;
		Date timestamp = new Date();

		MetadataReference reference = new MetadataReference();
		reference.setReferenceScope(scopeType);
		reference.setTableName(tableName);
		reference.setRowIdValue(rowIdValue);
		reference.setTimestamp(timestamp);
		reference.setMetadata(metadata);
		reference.setParentMetadata(metadata2);
		dao.create(reference);

		// Verify count
		long newCount = dao.countOf();
		TestCase.assertEquals(count + 1, newCount);

		// Verify saved metadata
		List<MetadataReference> queryMetadataReferenceList = dao
				.queryByMetadata(fileId, parentId);
		TestCase.assertNotNull(queryMetadataReferenceList);
		TestCase.assertEquals(1, queryMetadataReferenceList.size());
		MetadataReference queryMetadataReference = queryMetadataReferenceList
				.get(0);
		TestCase.assertEquals(scopeType,
				queryMetadataReference.getReferenceScope());
		TestCase.assertEquals(tableName,
				queryMetadataReference.getTableName());
		TestCase.assertNull(queryMetadataReference.getColumnName());
		TestCase.assertEquals(rowIdValue, queryMetadataReference
				.getRowIdValue().longValue());
		TestCase.assertEquals(timestamp,
				queryMetadataReference.getTimestamp());
		TestCase.assertEquals(fileId, queryMetadataReference.getFileId());
		TestCase.assertEquals(parentId, queryMetadataReference
				.getParentId().longValue());
		TestCase.assertNotNull(queryMetadataReference.getMetadata());
		TestCase.assertNotNull(queryMetadataReference.getParentMetadata());
	}

}
 
Example 13
Source File: TestAbstractBoard.java    From Bulldog with Apache License 2.0 4 votes vote down vote up
@Test
public void testGetI2cBus() {
	MockedBoard board = new MockedBoard();
	TestCase.assertNotNull(board.getI2cBus("I2C1"));
	TestCase.assertNull(board.getI2cBus("I2C999"));
}
 
Example 14
Source File: MetadataReferenceUtils.java    From geopackage-android with MIT License 4 votes vote down vote up
/**
 * Test create
 * 
 * @param geoPackage
 * @throws SQLException
 */
public static void testCreate(GeoPackage geoPackage) throws SQLException {

	MetadataReferenceDao dao = geoPackage.getMetadataReferenceDao();
	MetadataDao metadataDao = geoPackage.getMetadataDao();

	if (dao.isTableExists()) {
		// Get current count
		long count = dao.countOf();

		long fileId = 5555;
		long parentId = 5556;

		// Create new metadata
		Metadata metadata = new Metadata();
		metadata.setId(fileId);
		metadata.setMetadataScope(MetadataScopeType.FEATURE);
		metadata.setStandardUri("https://www.nga.mil");
		metadata.setMimeType("text/xml");
		metadata.setMetadata("Create metadata text");
		metadataDao.create(metadata);

		Metadata metadata2 = new Metadata();
		metadata2.setId(parentId);
		metadata2.setMetadataScope(MetadataScopeType.FEATURE_TYPE);
		metadata2.setStandardUri("https://www.nga.mil");
		metadata2.setMimeType("text/xml");
		metadata2.setMetadata("Create metadata text 2");
		metadataDao.create(metadata2);

		ReferenceScopeType scopeType = ReferenceScopeType.ROW;
		String tableName = "CREATE_TABLE_NAME";
		long rowIdValue = 50;
		Date timestamp = new Date();

		MetadataReference reference = new MetadataReference();
		reference.setReferenceScope(scopeType);
		reference.setTableName(tableName);
		reference.setRowIdValue(rowIdValue);
		reference.setTimestamp(timestamp);
		reference.setMetadata(metadata);
		reference.setParentMetadata(metadata2);
		dao.create(reference);

		// Verify count
		long newCount = dao.countOf();
		TestCase.assertEquals(count + 1, newCount);

		// Verify saved metadata
		List<MetadataReference> queryMetadataReferenceList = dao
				.queryByMetadata(fileId, parentId);
		TestCase.assertNotNull(queryMetadataReferenceList);
		TestCase.assertEquals(1, queryMetadataReferenceList.size());
		MetadataReference queryMetadataReference = queryMetadataReferenceList
				.get(0);
		TestCase.assertEquals(scopeType,
				queryMetadataReference.getReferenceScope());
		TestCase.assertEquals(tableName,
				queryMetadataReference.getTableName());
		TestCase.assertNull(queryMetadataReference.getColumnName());
		TestCase.assertEquals(rowIdValue, queryMetadataReference
				.getRowIdValue().longValue());
		TestCase.assertEquals(timestamp,
				queryMetadataReference.getTimestamp());
		TestCase.assertEquals(fileId, queryMetadataReference.getFileId());
		TestCase.assertEquals(parentId, queryMetadataReference
				.getParentId().longValue());
		TestCase.assertNotNull(queryMetadataReference.getMetadata());
		TestCase.assertNotNull(queryMetadataReference.getParentMetadata());
	}

}
 
Example 15
Source File: TestUtils.java    From geopackage-java with MIT License 4 votes vote down vote up
/**
 * Validate the integrity and keys of the GeoPackage
 * 
 * @param geoPackage
 */
public static void validateGeoPackage(GeoPackage geoPackage) {
	TestCase.assertNull(geoPackage.foreignKeyCheck());
	TestCase.assertNull(geoPackage.integrityCheck());
	TestCase.assertNull(geoPackage.quickCheck());
}
 
Example 16
Source File: TileUtils.java    From geopackage-java with MIT License 4 votes vote down vote up
/**
 * Validate a tile row
 * 
 * @param dao
 * @param columns
 * @param tileRow
 */
private static void validateTileRow(TileDao dao, String[] columns,
		TileRow tileRow) {
	TestCase.assertEquals(columns.length, tileRow.columnCount());

	for (int i = 0; i < tileRow.columnCount(); i++) {
		TileColumn column = tileRow.getTable().getColumns().get(i);
		TestCase.assertEquals(i, column.getIndex());
		TestCase.assertEquals(columns[i], tileRow.getColumnName(i));
		TestCase.assertEquals(i, tileRow.getColumnIndex(columns[i]));
		int rowType = tileRow.getRowColumnType(i);
		Object value = tileRow.getValue(i);

		switch (rowType) {

		case ResultUtils.FIELD_TYPE_INTEGER:
			TestUtils.validateIntegerValue(value, column.getDataType());
			break;

		case ResultUtils.FIELD_TYPE_FLOAT:
			TestUtils.validateFloatValue(value, column.getDataType());
			break;

		case ResultUtils.FIELD_TYPE_STRING:
			TestCase.assertTrue(value instanceof String);
			break;

		case ResultUtils.FIELD_TYPE_BLOB:
			TestCase.assertTrue(value instanceof byte[]);
			break;

		case ResultUtils.FIELD_TYPE_NULL:
			TestCase.assertNull(value);
			break;

		}
	}

	TestCase.assertTrue(tileRow.getId() >= 0);
	TestCase.assertTrue(tileRow.getZoomLevel() >= 0);
	TestCase.assertTrue(tileRow.getTileColumn() >= 0);
	TestCase.assertTrue(tileRow.getTileRow() >= 0);
	byte[] tileData = tileRow.getTileData();
	TestCase.assertNotNull(tileData);
	TestCase.assertTrue(tileData.length > 0);

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

}
 
Example 17
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));

    }

}
 
Example 18
Source File: RelatedTablesUtils.java    From geopackage-java with MIT License 4 votes vote down vote up
/**
 * Validate a user row
 * 
 * @param columns
 *            array of columns
 * @param userRow
 *            user custom row
 */
public static void validateUserRow(String[] columns, UserCustomRow userRow) {

	TestCase.assertEquals(columns.length, userRow.columnCount());

	for (int i = 0; i < userRow.columnCount(); i++) {
		UserCustomColumn column = userRow.getTable().getColumns().get(i);
		GeoPackageDataType dataType = column.getDataType();
		TestCase.assertEquals(i, column.getIndex());
		TestCase.assertEquals(columns[i], userRow.getColumnName(i));
		TestCase.assertEquals(i, userRow.getColumnIndex(columns[i]));
		int rowType = userRow.getRowColumnType(i);
		Object value = userRow.getValue(i);

		switch (rowType) {

		case ResultUtils.FIELD_TYPE_INTEGER:
			TestUtils.validateIntegerValue(value, column.getDataType());
			break;

		case ResultUtils.FIELD_TYPE_FLOAT:
			TestUtils.validateFloatValue(value, column.getDataType());
			break;

		case ResultUtils.FIELD_TYPE_STRING:
			if (dataType == GeoPackageDataType.DATE
					|| dataType == GeoPackageDataType.DATETIME) {
				TestCase.assertTrue(value instanceof Date);
				Date date = (Date) value;
				DateConverter converter = DateConverter.converter(dataType);
				String dateString = converter.stringValue(date);
				TestCase.assertEquals(date.getTime(),
						converter.dateValue(dateString).getTime());
			} else {
				TestCase.assertTrue(value instanceof String);
			}
			break;

		case ResultUtils.FIELD_TYPE_BLOB:
			TestCase.assertTrue(value instanceof byte[]);
			break;

		case ResultUtils.FIELD_TYPE_NULL:
			TestCase.assertNull(value);
			break;

		}
	}

}
 
Example 19
Source File: FeatureUtils.java    From geopackage-android with MIT License 4 votes vote down vote up
/**
 * Test delete
 *
 * @param geoPackage GeoPackage
 * @throws SQLException upon error
 */
public static void testDelete(GeoPackage geoPackage) throws SQLException {

    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();
            int count = cursor.getCount();
            if (count > 0) {

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

                FeatureRow featureRow = cursor.getRow();
                cursor.close();

                // Delete row
                try {
                    TestCase.assertEquals(1, dao.delete(featureRow));
                } catch (SQLiteException e) {
                    if (TestUtils.isFutureSQLiteException(e)) {
                        continue;
                    } else {
                        throw e;
                    }
                }

                // Verify deleted
                FeatureRow queryFeatureRow = dao.queryForIdRow(featureRow
                        .getId());
                TestCase.assertNull(queryFeatureRow);
                cursor = dao.queryForAll();
                TestCase.assertEquals(count - 1, cursor.getCount());
                cursor.close();
            }
            cursor.close();
        }
    }
}
 
Example 20
Source File: TileMatrixUtils.java    From geopackage-android with MIT License 4 votes vote down vote up
/**
 * Test delete
 * 
 * @param geoPackage
 * @throws SQLException
 */
public static void testDelete(GeoPackage geoPackage) throws SQLException {

	TileMatrixDao dao = geoPackage.getTileMatrixDao();
	if (dao.isTableExists()) {
		List<TileMatrix> results = dao.queryForAll();

		if (!results.isEmpty()) {

			// Choose random tile matrix
			int random = (int) (Math.random() * results.size());
			TileMatrix tileMatrix = results.get(random);

			// Delete the tile matrix
			dao.delete(tileMatrix);

			// Verify deleted
			TileMatrix queryTileMatrix = dao.queryForId(tileMatrix.getId());
			TestCase.assertNull(queryTileMatrix);

			// Prepared deleted
			results = dao.queryForAll();
			if (!results.isEmpty()) {

				// Choose random tile matrix
				random = (int) (Math.random() * results.size());
				tileMatrix = results.get(random);

				// Find which tile matrix to delete
				QueryBuilder<TileMatrix, TileMatrixKey> qb = dao
						.queryBuilder();
				qb.where().eq(TileMatrix.COLUMN_ZOOM_LEVEL,
						tileMatrix.getZoomLevel());
				PreparedQuery<TileMatrix> query = qb.prepare();
				List<TileMatrix> queryResults = dao.query(query);
				int count = queryResults.size();

				// Delete
				DeleteBuilder<TileMatrix, TileMatrixKey> db = dao
						.deleteBuilder();
				db.where().eq(TileMatrix.COLUMN_ZOOM_LEVEL,
						tileMatrix.getZoomLevel());
				PreparedDelete<TileMatrix> deleteQuery = db.prepare();
				int deleted = dao.delete(deleteQuery);

				TestCase.assertEquals(count, deleted);

			}
		}
	}
}