Example usage for java.lang AssertionError getMessage

List of usage examples for java.lang AssertionError getMessage

Introduction

In this page you can find the example usage for java.lang AssertionError getMessage.

Prototype

public String getMessage() 

Source Link

Document

Returns the detail message string of this throwable.

Usage

From source file:net.javacrumbs.jsonunit.spring.ExampleControllerTest.java

@Test
public void isObjectShouldFailOnArray() throws Exception {
    try {//from w ww .  j a v a  2  s .  c  o  m
        exec().andExpect(json().node("result.array").isObject());
        failIfNoException();
    } catch (AssertionError e) {
        assertEquals("Node \"result.array\" is not an object. The actual value is '[1,2,3]'.", e.getMessage());
    }
}

From source file:net.cpollet.jixture.asserts.JixtureAssert.java

public JixtureAssert containsExactly(List<Fixture> fixtures) {
    List<String> errors = new ArrayList<String>(2);

    try {/*from   w  w w. jav  a 2s  . co  m*/
        containsAtLeast(fixtures);
    } catch (AssertionError assertionError) {
        errors.add(assertionError.getMessage());
    }

    try {
        containsAtMost(fixtures);
    } catch (AssertionError assertionError) {
        errors.add(assertionError.getMessage());
    }

    if (0 < errors.size()) {
        throw new AssertionError(StringUtils.collectionToCommaDelimitedString(errors));
    }

    return this;
}

From source file:jackrabbit.app.AppTest.java

@Before
public void setUp() throws Exception {
    RepositoryFactory srcRf = new RepositoryFactoryImpl(srcConf, srcRepoDir);
    RepositoryFactory destRf = new RepositoryFactoryImpl(destConf, destRepoDir);
    try {/*from   ww  w . j av  a  2  s  .  c  o m*/
        src = srcRf.getRepository();
    } catch (AssertionError e) {
        //if the src repository was indexed using pre-2.4.1 Lucene, an assert error about del count mismatch may occur (https://issues.apache.org/jira/browse/LUCENE-1474).
        log.error(e.getMessage(), e);
    }
    dest = destRf.getRepository();
    SimpleCredentials credentials = new SimpleCredentials("username", "password".toCharArray());
    if (src == null)
        return;
    srcSf = new SessionFactoryImpl(src, credentials);
    destSf = new SessionFactoryImpl(dest, credentials);
    srcSession = srcSf.getSession();
    destSession = destSf.getSession();
    RepositoryManager.registerCustomNodeTypes(destSession, cndPath);

}

From source file:net.javacrumbs.jsonunit.spring.ExampleControllerTest.java

@Test
public void isArrayShouldFailOnNotArray() throws Exception {
    try {//from  w ww  .j a  va 2s  . c  o m
        exec().andExpect(json().node("result.string").isArray());
        failIfNoException();
    } catch (AssertionError e) {
        assertEquals("Node \"result.string\" is not an array. The actual value is '\"stringValue\"'.",
                e.getMessage());
    }
}

From source file:tds.student.sql.repository.ResponseRepositoryTest.java

@Test
@Ignore("Autowire issues")
public final void testInsertItems() throws Exception {
    System.out.println();//w w w.  j  ava2  s . com
    _logger.info("Test of getNextItemGroup (Connection connection, UUID oppkey, _Ref<String> errorRef) "
            + "for AdaptiveSelector2013: ");
    System.out.println();

    try {//''
         //String OPPKEY = "a1674ef0-9042-428e-beab-9f082bdc93f8"; // This is student with 3 previous items!
        String OPPKEY = "79CAF065-40F4-43CB-9290-E1B2580AE8DB";

        UUID oppkey = (UUID.fromString(OPPKEY));
        _logger.info("Oppkey =  " + OPPKEY);

        _Ref<String> errorRef = new _Ref<>();

        OpportunityInstance oppInstance = new OpportunityInstance(oppkey,
                //               UUID.fromString("C60BDD2F-D4C4-4011-93BA-E046A4D3E794"),
                //               UUID.fromString("A222C529-6F4A-4CDD-B2F2-8FC4A9C39E88"));
                UUID.fromString("6BEDFAFD-AC1E-495F-BAB3-AA577A3530C1"), // sessionkey
                UUID.fromString("DBB38430-9499-4BF3-BB6D-FDC7D9AA090F")); // browserkey

        AdaptiveGroup adaptiveGroup = new AdaptiveGroup();
        adaptiveGroup.setPage(1);
        adaptiveGroup.setBankKey(0);
        adaptiveGroup.setGroupID("I-200-9727");
        adaptiveGroup.setSegmentPosition(1);
        adaptiveGroup.setSegmentID("CAT-M3-ONON-S1-A1-MATH-3");
        adaptiveGroup.setNumItemsRequired(0);

        try {
            OpportunityItems oppItems = responseRepository.insertItems(oppInstance, adaptiveGroup, false);

            final String SQL_QUERY1 = "select *  from ${ArchiveDB}.systemerrors "
                    + " where _fk_session = ${sessionID} and _fk_testopportunity = ${oppkey}";

            SqlParametersMaps parms1 = (new SqlParametersMaps()).put("sessionID", oppInstance.getSessionKey())
                    .put("oppkey", oppInstance.getKey());
            SingleDataResultSet result = _myDllHelper
                    .executeStatement(_connection, _myDllHelper.fixDataBaseNames(SQL_QUERY1), parms1, true)
                    .getResultSets().next();
            DbResultRecord record = (result.getCount() > 0 ? result.getRecords().next() : null);

            if (record != null) {
                System.out.println(String.format("Application: %s", record.<String>get("application")));
                System.out.println(String.format("Procname: %s", record.<String>get("procname")));
                System.out.println(String.format("ErrorMessage: %s", record.<String>get("errormessage")));
                System.out.println(String.format("ServerID: %s", record.<String>get("serverid")));
                System.out.println(String.format("ClientName: %s", record.<String>get("clientname")));
                System.out.println(String.format("DBName: %s", record.<String>get("dbname")));
            } else {
                System.out.println(String.format("Record is empty: no records in ${ArchiveDB}.systemerrors"));
            }

        } catch (Exception e) {
            _logger.error(e.getMessage());
            System.out.println("Error: " + e.getMessage());
        }

        if (errorRef.get() != null && !errorRef.get().isEmpty()) {
            _logger.error(errorRef.get());
            System.out.println(String.format(errorRef.get()));
            throw new ReturnStatusException(errorRef.get());
        }

        //         // TODO delete System.out.println() !!!
        //         System.out.println(String.format("groupID: %s", itemGr.groupID));
        //         System.out.println(String.format("itemsRequired: %s", itemGr.getNumRequired()));
        //         System.out.println(String.format("maxReqItems: %s", itemGr.getTestLength()));
        //         _logger.info(String.format("groupID: %s", itemGr.groupID));
        //         _logger.info(String.format("itemsRequired: %s", itemGr.getNumRequired()));
        //         _logger.info(String.format("maxReqItems: %s", itemGr.getTestLength()));

        //         List<TestItem> items = itemGr.getItems();
        //         int itemsNumber = items.size();
        //         System.out.println(String.format("Number of items: %s",
        //               itemsNumber));
        //         _logger.info(String.format("Number of items: %s", itemsNumber));

    } catch (Exception e) {
        System.out.println("Exception in the testGetNextItemGroup test: " + e);
        if (e instanceof java.lang.NullPointerException) {
            System.out.println("Stack: " + e.getStackTrace());
        }
        _logger.error(e.getMessage());
        throw e;
    } catch (AssertionError error) {
        System.out.println("AssertionError in the testGetNextItemGroup test: " + error);
        _logger.error(error.getMessage());
        throw error;
    }
}

From source file:com.alliander.osgp.acceptancetests.devicemanagement.RemoveDeviceSteps.java

@DomainStep("the remove device response should return (.*)")
public boolean thenTheResponseShouldReturn(final String result) {
    LOGGER.info("THEN: the remove device response should return {}.", result);

    if (result.toUpperCase().equals("OK")) {
        try {/*from   w w w.ja  v a 2  s.c o  m*/
            Assert.assertNotNull("Response should not be null", this.response);
            Assert.assertNull("Throwable should be null", this.throwable);
        } catch (final AssertionError e) {
            LOGGER.error("Exception [{}]: {}", e.getClass().getSimpleName(), e.getMessage());
            return false;
        }
    } else {
        try {
            Assert.assertNotNull("Throwable should not be null", this.throwable);
            Assert.assertEquals(result.toUpperCase(),
                    this.throwable.getCause().getClass().getSimpleName().toUpperCase());
        } catch (final AssertionError e) {
            LOGGER.error("Exception [{}]: {}", e.getClass().getSimpleName(), e.getMessage());
            return false;
        }
    }

    return true;
}

From source file:net.javacrumbs.jsonunit.spring.ExampleControllerTest.java

@Test
public void isEqualToShouldFailIfDoesNotEqual() throws Exception {
    try {/*from   w w w. j a v a2 s .com*/
        exec().andExpect(json().isEqualTo(CORRECT_JSON.replace("stringValue", "stringValue2")));
        failIfNoException();
    } catch (AssertionError e) {
        assertEquals("JSON documents are different:\n"
                + "Different value found in node \"result.string\". Expected \"stringValue2\", got \"stringValue\".\n",
                e.getMessage());
    }
}

From source file:net.javacrumbs.jsonunit.spring.ExampleControllerTest.java

@Test
public void isEqualToShouldFailIfNodeDoesNotEqual() throws Exception {
    try {//from  w  w  w.  j  ava 2  s.com
        exec().andExpect(json().node("result.string").isEqualTo("stringValue2"));
        failIfNoException();
    } catch (AssertionError e) {
        assertEquals("JSON documents are different:\n"
                + "Different value found in node \"result.string\". Expected \"stringValue2\", got \"stringValue\".\n",
                e.getMessage());
    }
}

From source file:tk.elevenk.restfulrobot.testcase.TestCase.java

/**
 * Validates the last response using the validations given in the test
 * script//from w ww .  java 2  s  . c  om
 * 
 * @return Boolean of whether the validations passed or failed
 */
public boolean validateResponse() {

    boolean passed = false;

    // check all validations and catch any assertion errors
    try {
        this.responses.get(responses.size() - 1)
                .validate(this.requests.get(requests.size() - 1).requestData.validations);
        this.result.setDetails(TestResult.MESSAGE_PASSED);
        this.result.setResultType(TestResult.TYPE_PASS);
        passed = true;
    } catch (AssertionError e) {
        logger.error(e.getMessage());
        this.result.setDetails(e.getMessage());
        this.result.setResultType(TestResult.TYPE_FAILURE);
    } catch (Exception e) {
        logger.error(ExceptionUtils.getStackTrace(e));
        this.result.setDetails(e.getMessage());
        this.result.setResultType(TestResult.TYPE_ERROR);
    }

    return passed;
}

From source file:com.enonic.cms.itest.content.ContentServiceImpl_updateContentTest.java

@Test
public void testUpdateContentNameTooLong() {
    UserEntity testUser = fixture.findUserByName("testuser");
    CreateContentCommand createCommand = createCreateContentCommand(ContentStatus.DRAFT.getKey(), testUser);
    ContentKey contentKey = contentService.createContent(createCommand);

    fixture.flushAndClearHibernateSesssion();

    ContentEntity persistedContent = contentDao.findByKey(contentKey);

    UpdateContentCommand command = createUpdateContentCommand(contentKey,
            persistedContent.getDraftVersion().getKey(), ContentStatus.DRAFT.getKey(), false, false);
    String newName = StringUtils.repeat("x", ContentNameValidator.CONTENT_NAME_MAX_LENGTH + 1);
    command.setContentName(newName);//from   w  w  w  . j  a  v  a 2  s .com

    try {
        contentService.updateContent(command);
        fail("Expected exception");
    } catch (AssertionError e) {
        throw e;
    } catch (Throwable e) {
        assertTrue(e instanceof UpdateContentException);
        assertTrue(e.getMessage().toLowerCase().contains("too long"));
    }
}