/** * Fails a test with no message. */ static public void fail() { fail(null); }
/** * @see #assertFile(File, String) */ static public void assertFile(File tstvalue) { assertFile(tstvalue, null); }
static public void assertDirectory(File tstvalue) { assertDirectory(tstvalue, null); }
/** * Formats failure for file assertions */ private static void failFile(File path, String actual, String expected, String message) { String formatted = ""; if(message != null) { formatted = message + " "; } fail(formatted + "expected <" + expected +"> but was <" + toString(path) + ">" +(expected!=null?"<" + expected +">":"")); }
@Test public void notReflexive() { NotReflexive notReflexive = new NotReflexive(); try { equivalenceTester() .addEquivalentGroup(notReflexive) .check(); fail("Expected EquivalenceAssertionError"); } catch (EquivalenceAssertionError e) { assertExpectedFailures(e, new ElementCheckFailure(NOT_REFLEXIVE, 0, 0, notReflexive)); } }
@Test @SuppressWarnings({"unchecked", "rawtypes", "OverlyStrongTypeCast"}) public void testNotComparableComparison() { try { comparisonTester() .addLesserGroup((List) newArrayList(5)) // cast to List in order to remove type safety of returned generic .addGreaterGroup("string") .check(); fail("Expected EquivalenceAssertionError"); } catch (EquivalenceAssertionError e) { assertExpectedFailures(e, new PairCheckFailure(COMPARE_CLASS_CAST_EXCEPTION, 0, 0, 5, 1, 0, "string"), new PairCheckFailure(COMPARE_CLASS_CAST_EXCEPTION, 1, 0, "string", 0, 0, 5)); } }
@Test public void testCreateExternalTable() throws Exception { File tempDir = createTempDir(); File dataFile = new File(tempDir, "test.txt"); Files.write("hello\nworld\n", dataFile, UTF_8); @Language("SQL") String createTableSql = format("" + "CREATE TABLE %s.%s.test_create_external (\n" + " name varchar\n" + ")\n" + "WITH (\n" + " external_location = '%s',\n" + " format = 'TEXTFILE'\n" + ")", getSession().getCatalog().get(), getSession().getSchema().get(), new Path(tempDir.toURI().toASCIIString()).toString()); assertUpdate(createTableSql); MaterializedResult actual = computeActual("SHOW CREATE TABLE test_create_external"); assertEquals(actual.getOnlyValue(), createTableSql); actual = computeActual("SELECT name FROM test_create_external"); assertEquals(actual.getOnlyColumnAsSet(), ImmutableSet.of("hello", "world")); assertUpdate("DROP TABLE test_create_external"); // file should still exist after drop assertFile(dataFile); deleteRecursively(tempDir.toPath(), ALLOW_INSECURE); }
@Test public void testSimple() throws Exception { final ModelConverter mr = modelResolver(); final Schema model = mr.resolve(new AnnotatedType(ModelWithJodaDateTime.class), new ModelConverterContextImpl(mr), null); assertNotNull(model); final Map<String, Schema> props = model.getProperties(); assertEquals(props.size(), 2); for (Map.Entry<String, Schema> entry : props.entrySet()) { final String name = entry.getKey(); final Schema prop = entry.getValue(); if ("name".equals(name)) { assertEquals(prop.getType(), "string"); } else if ("createdAt".equals(name)) { assertEquals(prop.getType(), "string"); assertEquals(prop.getFormat(), "date-time"); } else { fail(String.format("Unknown property '%s'", name)); } } }
@Test public void testStop() throws Exception { File staging = new File(temporary, "staging"); File storage = new File(temporary, "storage"); File quarantine = new File(temporary, "quarantine"); assertDirectory(staging); assertDirectory(storage); assertDirectory(quarantine); File file = store.getStagingFile(randomUUID()); store.createParents(file); assertFalse(file.exists()); assertTrue(file.createNewFile()); assertFile(file); store.stop(); assertFalse(file.exists()); assertFalse(staging.exists()); assertDirectory(storage); assertDirectory(quarantine); }
@Test public void testWriterRollback() assertDirectory(staging); assertEquals(staging.list(), new String[] {});
/** * @see #assertMaxLength(File, long, String) */ static public void assertMaxLength(File tstvalue, long expected) { assertMaxLength(tstvalue, expected, null); }
/** * @see #assertLength(File, long, String) */ static public void assertLength(File tstvalue, long expected) { assertLength(tstvalue, expected, null); }
/** * @see #assertMinLength(File, long, String) */ static public void assertMinLength(File tstvalue, long expected) { assertMinLength(tstvalue, expected, null); }
@Test public void equalsNullThrowsException() { EqualsNullThrowsException equalsNullThrowsException = new EqualsNullThrowsException(); try { equivalenceTester() .addEquivalentGroup(equalsNullThrowsException) .check(); fail("Expected EquivalenceAssertionError"); } catch (EquivalenceAssertionError e) { assertExpectedFailures(e, new ElementCheckFailure(EQUAL_NULL_EXCEPTION, 0, 0, equalsNullThrowsException)); } }
@Test @SuppressWarnings({"unchecked", "rawtypes", "OverlyStrongTypeCast"}) public void testNotComparableComparison() { try { comparisonTester() .addLesserGroup((List) newArrayList(5)) // cast to List in order to remove type safety of returned generic .addGreaterGroup("string") .check(); fail("Expected EquivalenceAssertionError"); } catch (EquivalenceAssertionError e) { assertExpectedFailures(e, new PairCheckFailure(COMPARE_CLASS_CAST_EXCEPTION, 0, 0, 5, 1, 0, "string"), new PairCheckFailure(COMPARE_CLASS_CAST_EXCEPTION, 1, 0, "string", 0, 0, 5)); } }
@Test public void testCorruption() throws Exception { assertEmptyStagingDirectory(); assertBackupStats(0, 0, 0); File file = new File(temporary, "corrupt"); Files.write("hello world", file, UTF_8); try { backupManager.submit(CORRUPTION_UUID, file).get(1, SECONDS); fail("expected exception"); } catch (ExecutionException wrapper) { PrestoException e = (PrestoException) wrapper.getCause(); assertEquals(e.getErrorCode(), RAPTOR_BACKUP_CORRUPTION.toErrorCode()); assertEquals(e.getMessage(), "Backup is corrupt after write: " + CORRUPTION_UUID); } File quarantineBase = storageService.getQuarantineFile(CORRUPTION_UUID); assertFile(new File(quarantineBase.getPath() + ".original")); assertFile(new File(quarantineBase.getPath() + ".restored")); assertBackupStats(0, 1, 1); assertEmptyStagingDirectory(); }
@Test @SpecAssertion(section = Sections.VALIDATIONAPI_BOOTSTRAPPING_VALIDATIONPROVIDER_PROVIDER, id = "d") public void testValidationProviderContainsNoArgConstructor() { ValidationProvider<?> validationProviderUnderTest = TestUtil.getValidationProviderUnderTest(); try { Constructor<?> constructor = validationProviderUnderTest.getClass().getConstructor(); assertTrue( Modifier.isPublic( constructor.getModifiers() ) ); } catch ( Exception e ) { fail( "The validation provider must have a public no arg constructor" ); } }
/** Formats failure for file assertions. */ private static void failFile(File path, String actual, String expected, String message) { String formatted = ""; if (message != null) { formatted = message + " "; } fail( formatted + "expected <" + expected + "> but was <" + toString(path) + ">" + (expected != null ? "<" + expected + ">" : "")); }
/** @see #assertMaxLength(File, long, String) */ public static void assertMaxLength(File tstvalue, long expected) { assertMaxLength(tstvalue, expected, null); }
/** @see #assertLength(File, long, String) */ public static void assertLength(File tstvalue, long expected) { assertLength(tstvalue, expected, null); }