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

The following examples show how to use junit.framework.TestCase#assertEquals() . 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: TestTransforms.java    From deeplearning4j with Apache License 2.0 6 votes vote down vote up
@Test
public void testTimeMathOpTransform() {
    Schema schema = new Schema.Builder().addColumnTime("column", DateTimeZone.UTC).build();

    Transform transform = new TimeMathOpTransform("column", MathOp.Add, 12, TimeUnit.HOURS); //12 hours: 43200000 milliseconds
    transform.setInputSchema(schema);

    Schema out = transform.transform(schema);
    assertEquals(1, out.getColumnMetaData().size());
    TestCase.assertEquals(ColumnType.Time, out.getType(0));

    assertEquals(Collections.singletonList((Writable) new LongWritable(1000 + 43200000)),
            transform.map(Collections.singletonList((Writable) new LongWritable(1000))));
    assertEquals(Collections.singletonList((Writable) new LongWritable(1452441600000L + 43200000)),
            transform.map(Collections.singletonList((Writable) new LongWritable(1452441600000L))));
}
 
Example 2
Source File: ConcSemanticsTests.java    From Concurnas with MIT License 6 votes vote down vote up
@Test
public void invalidClassPathEntry() throws IOException {
	ConccTestMockFileLoader mockFL = new ConccTestMockFileLoader();
	Path workDir = mockFL.fs.getPath("/work");
	Files.createDirectories(workDir);
	Files.createFile(mockFL.fs.getPath("myfile.class"));
	Conc concc = new Conc("-cp /work;/nonExist.class;/work/myfile.class;/work/thing.jar /work/MyFirstClass", mockFL);
	
	String got = concc.validateConcInstance(concc.getConcInstance()).validationErrs;
	String expect = "Classpath entry '/nonExist.class' does not exist\n" + 
			"Invalid classpath entry '/work/myfile.class', only directories or jar files can be class path entries\n" + 
			"Classpath entry '/work/thing.jar' does not exist\n" + 
			"Cannot find entry-point class to load: /work/MyFirstClass";
	
	TestCase.assertEquals(expect, got);
}
 
Example 3
Source File: GeoPackageExample.java    From geopackage-android with MIT License 6 votes vote down vote up
private void validateNGAExtensions(GeoPackage geoPackage, boolean has)
        throws SQLException {

    ExtensionsDao extensionsDao = geoPackage.getExtensionsDao();

    TestCase.assertEquals(
            has && GEOMETRY_INDEX,
            extensionsDao.isTableExists()
                    && !extensionsDao.queryByExtension(
                    FeatureTableIndex.EXTENSION_NAME).isEmpty());
    TestCase.assertEquals(has && FEATURE_TILE_LINK,
            new FeatureTileTableLinker(geoPackage).has());
    TestCase.assertEquals(
            has && TILE_SCALING,
            extensionsDao.isTableExists()
                    && !extensionsDao.queryByExtension(
                    TileTableScaling.EXTENSION_NAME).isEmpty());
    TestCase.assertEquals(has && PROPERTIES, new PropertiesExtension(
            geoPackage).has());
    TestCase.assertEquals(has && CONTENTS_ID, new ContentsIdExtension(
            geoPackage).has());
    TestCase.assertEquals(has && FEATURE_STYLE, new FeatureStyleExtension(
            geoPackage).has());

}
 
Example 4
Source File: TestQueueMuxBatchmgr.java    From oodt with Apache License 2.0 6 votes vote down vote up
public void testKillJob() {
    try {
        ResourceNode node1 = new ResourceNode();
        ResourceNode node2 = new ResourceNode();

        JobSpec spec1 = this.getSpecFromQueue("queue-1");
        queue.executeRemotely(spec1, node1);

        JobSpec spec2 = this.getSpecFromQueue("queue-2");
        queue.executeRemotely(spec2, node2);
        //Make sure that one can kill a job, and the other job is running
        TestCase.assertTrue(queue.killJob(spec1.getJob().getId(), node1));
        TestCase.assertEquals(mock1.getCurrentJobSpec(),null);
        TestCase.assertEquals(mock2.getCurrentJobSpec(),spec2);
        //Make sure kill fails with bad queue
        TestCase.assertFalse(queue.killJob(this.getSpecFromQueue("queue-3").getJob().getId(), node1));
    } catch (JobExecutionException e) {
        TestCase.fail("Unexpected Exception: "+e.getMessage());
    }
}
 
Example 5
Source File: LoadPreferencesJobTest.java    From datasync with MIT License 6 votes vote down vote up
@Test
public void testLoadCompletePreferencesWithClearStart() throws Exception {
    UserPreferencesJava userPrefs = new UserPreferencesJava();
    userPrefs.clear();

    String[] args = {"-t", "LoadPreferences", "-c", "src/test/resources/basic_test_config.json"};
    Main.main(args);
    TestCase.assertEquals("https://sandbox.demo.socrata.com", userPrefs.getDomain());
    TestCase.assertEquals("[email protected]", userPrefs.getUsername());
    TestCase.assertEquals("OpenData", userPrefs.getPassword());
    TestCase.assertEquals("D8Atrg62F2j017ZTdkMpuZ9vY", userPrefs.getAPIKey());
    TestCase.assertEquals("[email protected]", userPrefs.getAdminEmail());
    TestCase.assertEquals(false, userPrefs.emailUponError());
    TestCase.assertEquals("", userPrefs.getLogDatasetID());
    TestCase.assertEquals("smtp.something.com", userPrefs.getOutgoingMailServer());
    TestCase.assertEquals("21", userPrefs.getSmtpPort());
    TestCase.assertEquals("47", userPrefs.getSslPort());
    TestCase.assertEquals("[email protected]", userPrefs.getSmtpUsername());
    TestCase.assertEquals("smtppass", userPrefs.getSmtpPassword());
    TestCase.assertEquals("10", userPrefs.getFilesizeChunkingCutoffMB());
    TestCase.assertEquals("10000", userPrefs.getNumRowsPerChunk());
}
 
Example 6
Source File: EnableCompassTest.java    From metrics with Apache License 2.0 6 votes vote down vote up
@Test
public void test() {
    this.metricsTestService.testCompass1();

    Compass compass = MetricManager.getCompass("test",
        MetricName.build("ascp.upcp-scitem.metrics-annotation.compass.test1")
            .tagged("purpose", "test"));

    long successCount = compass.getSuccessCount();
    TestCase.assertEquals(1, successCount);
    long count = compass.getCount();
    TestCase.assertEquals(1, count);

    try {
        this.metricsTestService.testCompass1();
        this.metricsTestService.testCompass2();
        TestCase.fail();
    } catch (Exception e) {
        //ignore
    }

    successCount = compass.getSuccessCount();
    TestCase.assertEquals(2, successCount);
    count = compass.getCount();
    TestCase.assertEquals(3, count);
}
 
Example 7
Source File: ConccToConc.java    From Concurnas with MIT License 6 votes vote down vote up
@Test
public void testOneLineFileNoSubproc() throws Throwable {
	
	Path tempDirWithPrefix = Files.createTempDirectory("c2cJar");
	try {
		Path bindir = tempDirWithPrefix.resolve("bin");
		Files.createDirectories(bindir);
		Path srcdir = tempDirWithPrefix.resolve("src");
		Files.createDirectories(srcdir);
		
		Path myClass = srcdir.resolve("MyClass.conc"); 
		Files.write(myClass, ListMaker.make("def main() => System.err.println('hey there')"), StandardCharsets.UTF_8);
		
		Concc concc = new Concc(String.format("-d %s %s", bindir, srcdir));
		
		TestCase.assertEquals("", concc.doit());
		
		Path myclass = bindir.resolve(Paths.get("MyClass.class"));
		
		Conc conc = new Conc(myclass.toString());//execute
		ConcExeTests.checkOutput(conc, "hey there");
		
	}finally {
		Utils.deleteDirectory(tempDirWithPrefix.toFile());
	}
}
 
Example 8
Source File: GeoPackageGeometryDataUtils.java    From geopackage-java with MIT License 5 votes vote down vote up
/**
 * Compare the two compound curves for equality
 * 
 * @param expected
 * @param actual
 * @parma delta
 */
private static void compareCompoundCurve(CompoundCurve expected,
		CompoundCurve actual, double delta) {

	compareBaseGeometryAttributes(expected, actual);
	TestCase.assertEquals(expected.numLineStrings(),
			actual.numLineStrings());
	for (int i = 0; i < expected.numLineStrings(); i++) {
		compareLineString(expected.getLineStrings().get(i), actual
				.getLineStrings().get(i), delta);
	}
}
 
Example 9
Source File: FullModelComparisons.java    From deeplearning4j with Apache License 2.0 5 votes vote down vote up
@Test
public void cnnBatchNormLargerTest() throws IOException, UnsupportedKerasConfigurationException,
        InvalidKerasConfigurationException {

    String modelPath = "modelimport/keras/fullconfigs/cnn_batch_norm/cnn_batch_norm_medium.h5";

    KerasSequentialModel kerasModel = new KerasModel().modelBuilder()
            .modelHdf5Filename(Resources.asFile(modelPath).getAbsolutePath())
            .enforceTrainingConfig(false)
            .buildSequential();

    MultiLayerNetwork model = kerasModel.getMultiLayerNetwork();
    model.init();

    System.out.println(model.summary());

    INDArray input = Nd4j.createFromNpyFile(Resources.asFile("modelimport/keras/fullconfigs/cnn_batch_norm/input.npy"));
    input = input.permute(0, 3, 1, 2);
    assertTrue(Arrays.equals(input.shape(), new long[] {5, 1, 48, 48}));

    INDArray output = model.output(input);

    INDArray kerasOutput = Nd4j.createFromNpyFile(Resources.asFile("modelimport/keras/fullconfigs/cnn_batch_norm/predictions.npy"));

    for (int i = 0; i < 5; i++) {
        // TODO this should be a little closer
        TestCase.assertEquals(output.getDouble(i), kerasOutput.getDouble(i), 1e-2);
    }
}
 
Example 10
Source File: SecurePayServiceTest.java    From scipio-erp with Apache License 2.0 5 votes vote down vote up
public void testdoCredit() throws Exception{
    Debug.logInfo("=====[testdoCredit] starting....", module);
    try {
        Map<String, Object> serviceInput = UtilMisc.toMap(
                "paymentConfig", configFile,
                "billToParty", billToParty,
                "billToEmail", emailAddr,
                "orderItems", orderItems,
                "creditCard", creditCard,
                "billingAddress", billingAddress,
                "referenceCode", orderId,
                "currency", "AUD"
       );
        serviceInput.put("creditAmount", creditAmount);
        // run the service
        Map<String, Object> result = dispatcher.runSync("ofbScCCCredit",serviceInput);
        // verify the results
        String responseMessage = (String) result.get(ModelService.RESPONSE_MESSAGE);
        Debug.logInfo("[testdoCredit] responseMessage: " + responseMessage, module);
        TestCase.assertEquals("Service result is success", ModelService.RESPOND_SUCCESS, responseMessage);

        if (((Boolean) result.get("creditResult")).equals(Boolean.FALSE)) {          // returnCode ok?
            Debug.logInfo("[testdoCredit] Error Messages from SecurePay: " + result.get("internalRespMsgs"), module);
            TestCase.fail("Returned messages:" + result.get("internalRespMsgs"));
        } else {
            Debug.logInfo("[testdoCredit] Result from SecurePay: " + result, module);
        }

    } catch (GenericServiceException ex) {
        TestCase.fail(ex.getMessage());
    }
}
 
Example 11
Source File: TestMethodRewriteModification.java    From tracing-framework with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
public void expect(int index, Object... values) {
    TestCase.assertEquals(Lists.newArrayList(values), advised.get(index));
}
 
Example 12
Source File: FIFOSchedulerTest.java    From Explorer with Apache License 2.0 4 votes vote down vote up
public void testAbort() throws InterruptedException{
	Scheduler s = schedulerSvc.createOrGetFIFOScheduler("test");
	assertEquals(0, s.getJobsRunning().size());
	assertEquals(0, s.getJobsWaiting().size());
	
	Job job1 = new SleepingJob("job1", null, 500);
	Job job2 = new SleepingJob("job2", null, 500);
	
	s.submit(job1);
	s.submit(job2);
	
	Thread.sleep(200);
	
	job1.abort();
	job2.abort();
	
	Thread.sleep(200);
	
	TestCase.assertEquals(Job.Status.ABORT, job1.getStatus());
	TestCase.assertEquals(Job.Status.ABORT, job2.getStatus());
	
	assertTrue((500 > (Long)job1.getReturn()));
	assertEquals(null, job2.getReturn());
	
		
}
 
Example 13
Source File: CryptoUtilTest.java    From datasync with MIT License 4 votes vote down vote up
@Test
public void testObfuscationRoundtrips() {
    for(String x : new String[] { "hello", "smiling gnus are happy", "¥€$", "", "bleh" }) {
        TestCase.assertEquals(x, CryptoUtil.deobfuscate(CryptoUtil.obfuscate(x), null));
    }
}
 
Example 14
Source File: AbstractInterfaceConfigTest.java    From dubbo-2.6.5 with Apache License 2.0 4 votes vote down vote up
@Test
public void testConnections() throws Exception {
    InterfaceConfig interfaceConfig = new InterfaceConfig();
    interfaceConfig.setConnections(1);
    TestCase.assertEquals(1, interfaceConfig.getConnections().intValue());
}
 
Example 15
Source File: TopTestUtil.java    From rolling-metrics with Apache License 2.0 4 votes vote down vote up
public static void checkOrder(Top top, Position... positions) {
    TestCase.assertEquals(Arrays.asList(positions), top.getPositionsInDescendingOrder());
}
 
Example 16
Source File: JavaUrlCodecTest.java    From swellrt with Apache License 2.0 4 votes vote down vote up
public void testEncodingNotEscaped() throws URIEncoderDecoder.EncodingException {
  TestCase.assertEquals(NOT_ESCAPED, encoder.encode(NOT_ESCAPED));
}
 
Example 17
Source File: GeometryColumnsUtils.java    From geopackage-java with MIT License 4 votes vote down vote up
/**
 * Test delete
 * 
 * @param geoPackage
 * @throws SQLException
 */
public static void testDelete(GeoPackage geoPackage) throws SQLException {

	GeometryColumnsDao dao = geoPackage.getGeometryColumnsDao();

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

		if (!results.isEmpty()) {

			// Choose random geometry columns
			int random = (int) (Math.random() * results.size());
			GeometryColumns geometryColumns = results.get(random);

			// Delete the geometry columns
			dao.delete(geometryColumns);

			// Verify deleted
			GeometryColumns queryGeometryColumns = dao
					.queryForId(geometryColumns.getId());
			TestCase.assertNull(queryGeometryColumns);

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

				// Choose random geometry columns
				random = (int) (Math.random() * results.size());
				geometryColumns = results.get(random);

				// Find which geometry columns to delete
				QueryBuilder<GeometryColumns, TableColumnKey> qb = dao
						.queryBuilder();
				qb.where().eq(GeometryColumns.COLUMN_GEOMETRY_TYPE_NAME,
						geometryColumns.getGeometryType().getName());
				PreparedQuery<GeometryColumns> query = qb.prepare();
				List<GeometryColumns> queryResults = dao.query(query);
				int count = queryResults.size();

				// Delete
				DeleteBuilder<GeometryColumns, TableColumnKey> db = dao
						.deleteBuilder();
				db.where().eq(GeometryColumns.COLUMN_GEOMETRY_TYPE_NAME,
						geometryColumns.getGeometryType().getName());
				PreparedDelete<GeometryColumns> deleteQuery = db.prepare();
				int deleted = dao.delete(deleteQuery);

				TestCase.assertEquals(count, deleted);

			}
		}
	}
}
 
Example 18
Source File: GeoPackageTestUtils.java    From geopackage-java with MIT License 4 votes vote down vote up
/**
 * Test the GeoPackage vacuum
 * 
 * @param geoPackage
 *            GeoPackage
 */
public static void testVacuum(GeoPackage geoPackage) {

	String path = geoPackage.getPath();
	File file = new File(path);
	long size = file.length();

	for (String table : geoPackage.getTables()) {

		geoPackage.deleteTable(table);

		TestCase.assertEquals(size, file.length());

		geoPackage.vacuum();

		long newSize = file.length();
		TestCase.assertTrue(size > newSize);
		size = newSize;

	}

}
 
Example 19
Source File: GuardUtils.java    From netbeans with Apache License 2.0 4 votes vote down vote up
public static void verifyPositions(TestCase test, GuardedSection gs, int start, int end) {
    test.assertEquals("start position", start, gs.getStartPosition().getOffset());
    test.assertEquals("end position", end, gs.getEndPosition().getOffset());
}
 
Example 20
Source File: AssertHelperTests.java    From textuml with Eclipse Public License 1.0 4 votes vote down vote up
public void testOneWord() {
    TestCase.assertEquals("foo", AssertHelper.trim("foo"));
    TestCase.assertEquals("foo", AssertHelper.trim("foo "));
    TestCase.assertEquals("foo", AssertHelper.trim(" foo"));
    TestCase.assertEquals("foo", AssertHelper.trim(" foo "));
}