/** * Fails a test with no message. */ static public void fail() { fail(null); }
/** Fails a test with no message. */ public static void fail() { fail(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 +">":"")); }
/** * @param tstvalue * @param string * @param string2 * @param message */ private static void failSecurity(Exception e, File path, String actual, String expected, String message) { String formatted = ""; if(message != null) { formatted = message + " "; } fail(formatted + "expected <" + expected +"> but was <" + toString(path) + ">" +"<" + (e!=null && e.getMessage()!=null && e.getMessage().length()>0 ?e.getMessage() :"not authorized by JVM") + ">"); }
/** 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 + ">" : "")); }
/** * @param tstvalue * @param string * @param string2 * @param message */ private static void failSecurity( Exception e, File path, String actual, String expected, String message) { String formatted = ""; if (message != null) { formatted = message + " "; } fail( formatted + "expected <" + expected + "> but was <" + toString(path) + ">" + "<" + (e != null && e.getMessage() != null && e.getMessage().length() > 0 ? e.getMessage() : "not authorized by JVM") + ">"); }
@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)); } } }
private void waitForAndAssertResponse(ListenableFuture<Response> responseFuture) throws InterruptedException, java.util.concurrent.ExecutionException { Response response = responseFuture.get(); if (500 == response.getStatusCode()) { logger.debug("==============\n" + "500 response from call\n" + "Headers:" + response.getHeaders() + "\n" + "==============\n"); assertEquals(response.getStatusCode(), 500, "Should have 500 status code"); assertTrue(response.getHeader("X-Exception").contains("invalid.chunk.length"), "Should have failed due to chunking"); fail("HARD Failing the test due to provided InputStreamBodyGenerator, chunking incorrectly:" + response.getHeader("X-Exception")); } else { assertEquals(response.getResponseBodyAsBytes(), LARGE_IMAGE_BYTES); } } }
@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" ); } }
@Test @SpecAssertion(section = "4.4.4.2", 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" ); } }
@Override public void corruption(long bytes, String reason) { fail(String.format("corruption of %s bytes: %s", bytes, reason)); }
@Override public void corruption(long bytes, String reason) { fail(String.format("corruption of %s bytes: %s", bytes, reason)); }
@Override AtlasEntityHeader getByUniqueAttributes(AtlasEntityType entityType, String qualifiedName, Map<String, Object> attrValues) { try { if (StringUtils.isEmpty(entityFileName)) { return null; } return getEntityHeaderFromFile(entityFileName); } catch (IOException e) { fail(entityFileName + " could not be loaded."); return null; } } }
@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 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 public void equalsNull() { EqualsNull equalsNull = new EqualsNull(); try { equivalenceTester() .addEquivalentGroup(equalsNull) .check(); fail("Expected EquivalenceAssertionError"); } catch (EquivalenceAssertionError e) { assertExpectedFailures(e, new ElementCheckFailure(EQUAL_TO_NULL, 0, 0, equalsNull)); } }
@Test public void equalsNull() { EqualsNull equalsNull = new EqualsNull(); try { equivalenceTester() .addEquivalentGroup(equalsNull) .check(); fail("Expected EquivalenceAssertionError"); } catch (EquivalenceAssertionError e) { assertExpectedFailures(e, new ElementCheckFailure(EQUAL_TO_NULL, 0, 0, equalsNull)); } }
@Test public void equalsUnrelatedClassThrowsException() { EqualsOtherClassThrowsException equalsOtherClassThrowsException = new EqualsOtherClassThrowsException(); try { equivalenceTester() .addEquivalentGroup(equalsOtherClassThrowsException) .check(); fail("Expected EquivalenceAssertionError"); } catch (EquivalenceAssertionError e) { assertExpectedFailures(e, new ElementCheckFailure(EQUAL_TO_UNRELATED_CLASS_CLASS_CAST_EXCEPTION, 0, 0, equalsOtherClassThrowsException)); } }
@Test public void equalsUnrelatedClass() { EqualsUnrelatedClass equalsUnrelatedClass = new EqualsUnrelatedClass(); try { equivalenceTester() .addEquivalentGroup(equalsUnrelatedClass) .check(); fail("Expected EquivalenceAssertionError"); } catch (EquivalenceAssertionError e) { assertExpectedFailures(e, new ElementCheckFailure(EQUAL_TO_UNRELATED_CLASS, 0, 0, equalsUnrelatedClass)); } }
@Test public void equalsUnrelatedClassThrowsException() { EqualsOtherClassThrowsException equalsOtherClassThrowsException = new EqualsOtherClassThrowsException(); try { equivalenceTester() .addEquivalentGroup(equalsOtherClassThrowsException) .check(); fail("Expected EquivalenceAssertionError"); } catch (EquivalenceAssertionError e) { assertExpectedFailures(e, new ElementCheckFailure(EQUAL_TO_UNRELATED_CLASS_CLASS_CAST_EXCEPTION, 0, 0, equalsOtherClassThrowsException)); } }