Example usage for junit.framework Assert assertSame

List of usage examples for junit.framework Assert assertSame

Introduction

In this page you can find the example usage for junit.framework Assert assertSame.

Prototype

static public void assertSame(Object expected, Object actual) 

Source Link

Document

Asserts that two objects refer to the same object.

Usage

From source file:org.apache.hive.service.cli.TestHiveSQLException.java

/**
 * Tests the conversion between the exception text with the simple cause and the
 * Throwable object/* w w  w. ja  v a 2s  . c  o m*/
 */
@Test
public void testExceptionMarshalling() throws Exception {
    Exception ex1 = createException();
    ex1.initCause(createSimpleCause());
    Throwable ex = HiveSQLException.toCause(HiveSQLException.toString(ex1));

    Assert.assertSame(RuntimeException.class, ex.getClass());
    Assert.assertEquals("exception1", ex.getMessage());
    Assert.assertSame(UnsupportedOperationException.class, ex.getCause().getClass());
    Assert.assertEquals("exception2", ex.getCause().getMessage());
}

From source file:org.apache.hive.service.cli.TestHiveSQLException.java

/**
 * Tests the conversion between the exception text with nested cause and
 * the Throwable object// w  w w. j  a  va2  s.c o m
 */
@Test
public void testNestedException() {
    Exception ex1 = createException();
    ex1.initCause(createNestedCause());
    Throwable ex = HiveSQLException.toCause(HiveSQLException.toString(ex1));

    Assert.assertSame(RuntimeException.class, ex.getClass());
    Assert.assertEquals("exception1", ex.getMessage());

    Assert.assertSame(UnsupportedOperationException.class, ex.getCause().getClass());
    Assert.assertEquals("exception2", ex.getCause().getMessage());

    Assert.assertSame(Exception.class, ex.getCause().getCause().getClass());
    Assert.assertEquals("exception3", ex.getCause().getCause().getMessage());
}

From source file:org.apache.hive.service.cli.TestHiveSQLException.java

/**
 * Tests the conversion of the exception with unknown source
 *//*ww w  .  j a va2s .c o  m*/
@Test
public void testExceptionWithUnknownSource() {
    Exception ex1 = createException();
    ex1.initCause(createSimpleCause());
    List<String> details = HiveSQLException.toString(ex1);

    // Simulate the unknown source
    String[] tokens = details.get(1).split(":");
    tokens[2] = null;
    tokens[3] = "-1";
    details.set(1, StringUtils.join(tokens, ":"));

    Throwable ex = HiveSQLException.toCause(details);

    Assert.assertSame(RuntimeException.class, ex.getClass());
    Assert.assertEquals("exception1", ex.getMessage());
    Assert.assertSame(UnsupportedOperationException.class, ex.getCause().getClass());
    Assert.assertEquals("exception2", ex.getCause().getMessage());
}

From source file:org.apache.hive.service.cli.TestHiveSQLException.java

/**
 * Tests the conversion of the exception from anonymous class
 *//*ww w .  j av  a  2 s . c om*/
@Test
public void testExceptionFromAnonymousClass() {
    Dummy d = new Dummy() {

        public void testExceptionConversion() {
            Exception ex1 = createException();
            ex1.initCause(createSimpleCause());
            Throwable ex = HiveSQLException.toCause(HiveSQLException.toString(ex1));

            Assert.assertSame(RuntimeException.class, ex.getClass());
            Assert.assertEquals("exception1", ex.getMessage());
            Assert.assertSame(UnsupportedOperationException.class, ex.getCause().getClass());
            Assert.assertEquals("exception2", ex.getCause().getMessage());
        }
    };

    d.testExceptionConversion();
}

From source file:org.testdwr.plain.Test.java

public boolean uploadLightlyMapped(ObjectWithLightClassMapping lightObj) {
    Assert.assertSame(lightObj.getClass(), ObjectWithLightClassMapping.class);
    Assert.assertSame(lightObj.obj.getClass(), ObjectWithLightClassMapping.class);
    Assert.assertSame(lightObj.array[0].getClass(), ObjectWithLightClassMapping.class);
    return true;//from   w  w  w  . j a va  2 s  .com
}

From source file:org.xwiki.extension.xar.XarExtensionHandlerTest.java

@Test
public void testInstallOnWiki() throws Throwable {
    getMockery().checking(new Expectations() {
        {/*  w  w  w. j a v a2  s.c  o  m*/
            oneOf(mockRightService).hasAccessLevel(with(equal("admin")),
                    with(equal("xwiki:XWiki.ExtensionUser")), with(equal("XWiki.XWikiPreferences")),
                    with(any(XWikiContext.class)));
            will(returnValue(true));
        }
    });

    XWikiDocument existingDocument = new XWikiDocument(new DocumentReference("wiki", "space", "page"));
    BaseObject object = new BaseObject();
    object.setXClassReference(new DocumentReference("wiki", "space", "class"));
    existingDocument.addXObject(object);
    existingDocument.setCreatorReference(new DocumentReference("wiki", "space", "existingcreator"));
    this.mockXWiki.saveDocument(existingDocument, "", true, getContext());

    // install

    install(this.localXarExtensiontId1, "wiki", this.contextUser);

    // validate

    // space.page
    XWikiDocument page = this.mockXWiki.getDocument(existingDocument.getDocumentReference(), getContext());

    Assert.assertFalse("Document wiki:space.page has not been saved in the database", page.isNew());

    Assert.assertNull(page.getXObject(object.getXClassReference()));

    Assert.assertEquals("Wrong content", "content", page.getContent());
    Assert.assertEquals("Wrong creator", new DocumentReference("wiki", "space", "existingcreator"),
            page.getCreatorReference());
    Assert.assertEquals("Wrong author", this.contextUser, page.getAuthorReference());
    Assert.assertEquals("Wrong content author", this.contextUser, page.getContentAuthorReference());
    Assert.assertEquals("Wrong version", "2.1", page.getVersion());
    Assert.assertFalse("Document is hidden", page.isHidden());

    BaseClass baseClass = page.getXClass();
    Assert.assertNotNull(baseClass.getField("property"));
    Assert.assertEquals("property", baseClass.getField("property").getName());
    Assert.assertSame(NumberClass.class, baseClass.getField("property").getClass());

    // space.pagewithattachment

    XWikiDocument pagewithattachment = this.mockXWiki
            .getDocument(new DocumentReference("wiki", "space", "pagewithattachment"), getContext());
    Assert.assertFalse(pagewithattachment.isNew());
    Assert.assertEquals("Wrong version", "2.1", pagewithattachment.getVersion());
    Assert.assertEquals("Wrong creator", this.contextUser, pagewithattachment.getCreatorReference());
    Assert.assertEquals("Wrong author", this.contextUser, pagewithattachment.getAuthorReference());
    Assert.assertEquals("Wrong content author", this.contextUser,
            pagewithattachment.getContentAuthorReference());

    XWikiAttachment attachment = pagewithattachment.getAttachment("attachment.txt");
    Assert.assertNotNull(attachment);
    Assert.assertEquals("attachment.txt", attachment.getFilename());
    Assert.assertEquals(18, attachment.getContentSize(getContext()));
    Assert.assertEquals("attachment content", IOUtils.toString(attachment.getContentInputStream(getContext())));
    Assert.assertEquals("xwiki:XWiki.ExtensionUser", attachment.getAuthor());

    // space1.page1

    XWikiDocument page1 = this.mockXWiki.getDocument(new DocumentReference("wiki", "space1", "page1"),
            getContext());

    Assert.assertFalse("Document wiki:space1.page1 has not been saved in the database", page1.isNew());

    // translated.translated
    DocumentReference translatedReference = new DocumentReference("wiki", "translated", "translated");
    XWikiDocument defaultTranslated = this.mockXWiki.getDocument(translatedReference, getContext());

    Assert.assertNotNull("Document wiki:translated.translated has not been saved in the database",
            defaultTranslated);
    Assert.assertFalse("Document wiki:translated.translated has not been saved in the database",
            defaultTranslated.isNew());

    Assert.assertEquals("Wrong content", "default content", defaultTranslated.getContent());
    Assert.assertEquals("Wrong creator", this.contextUser, defaultTranslated.getCreatorReference());
    Assert.assertEquals("Wrong author", this.contextUser, defaultTranslated.getAuthorReference());
    Assert.assertEquals("Wrong content author", this.contextUser,
            defaultTranslated.getContentAuthorReference());
    Assert.assertEquals("Wrong version", "1.1", defaultTranslated.getVersion());

    // translated.translated.tr
    XWikiDocument translated = this.documents.get(translatedReference).get("tr");

    Assert.assertNotNull(
            "Document wiki:translated.translated in langauge tr has not been saved in the database",
            translated);
    Assert.assertFalse("Document wiki:translated.translated in langauge tr has not been saved in the database",
            translated.isNew());

    Assert.assertEquals("Wrong content", "tr content", translated.getContent());
    Assert.assertEquals("Wrong creator", this.contextUser, translated.getCreatorReference());
    Assert.assertEquals("Wrong author", this.contextUser, translated.getAuthorReference());
    Assert.assertEquals("Wrong content author", this.contextUser, translated.getContentAuthorReference());
    Assert.assertEquals("Wrong version", "1.1", translated.getVersion());

    // translated.translated.fr
    XWikiDocument translated2 = this.documents.get(translatedReference).get("fr");

    Assert.assertNotNull(
            "Document wiki:translated.translated in language fr has not been saved in the database",
            translated2);
    Assert.assertFalse("Document wiki:translated.translated in langauge fr has not been saved in the database",
            translated2.isNew());

    Assert.assertEquals("Wrong content", "fr content", translated2.getContent());
    Assert.assertEquals("Wrong creator", this.contextUser, translated2.getCreatorReference());
    Assert.assertEquals("Wrong author", this.contextUser, translated2.getAuthorReference());
    Assert.assertEquals("Wrong content author", this.contextUser, translated2.getContentAuthorReference());
    Assert.assertEquals("Wrong version", "1.1", translated2.getVersion());

    // space.hiddenpage

    XWikiDocument hiddenpage = this.mockXWiki.getDocument(new DocumentReference("wiki", "space", "hiddenpage"),
            getContext());

    Assert.assertNotNull("Document wiki:space.hiddenpage has not been saved in the database", hiddenpage);
    Assert.assertFalse("Document wiki:space.hiddenpage has not been saved in the database", hiddenpage.isNew());

    Assert.assertTrue("Document is not hidden", hiddenpage.isHidden());
}

From source file:org.xwiki.extension.xar.XarExtensionHandlerTest.java

@Test
public void testInstallOnWikiWithoutAuthor() throws Throwable {
    XWikiDocument existingDocument = new XWikiDocument(new DocumentReference("wiki", "space", "page"));
    BaseObject object = new BaseObject();
    object.setXClassReference(new DocumentReference("wiki", "space", "class"));
    existingDocument.addXObject(object);
    existingDocument.setCreatorReference(new DocumentReference("wiki", "space", "existingcreator"));
    this.mockXWiki.saveDocument(existingDocument, "", true, getContext());

    // install/*from   www.  j  a  v a  2s . c o  m*/

    install(this.localXarExtensiontId1, "wiki", null);

    // validate

    DocumentReference xarAuthorReference = new DocumentReference("wiki", "XWiki", "author");
    DocumentReference xarCreatorReference = new DocumentReference("wiki", "XWiki", "creator");
    DocumentReference xarContentAuthorReference = new DocumentReference("wiki", "XWiki", "contentAuthor");

    // space.page
    XWikiDocument page = this.mockXWiki.getDocument(existingDocument.getDocumentReference(), getContext());

    Assert.assertFalse("Document wiki:space.page has not been saved in the database", page.isNew());

    Assert.assertNull(page.getXObject(object.getXClassReference()));

    Assert.assertEquals("Wrong content", "content", page.getContent());
    Assert.assertEquals("Wrong creator", new DocumentReference("wiki", "space", "existingcreator"),
            page.getCreatorReference());
    Assert.assertEquals("Wrong author", xarAuthorReference, page.getAuthorReference());
    Assert.assertEquals("Wrong content author", xarContentAuthorReference, page.getContentAuthorReference());
    Assert.assertEquals("Wrong version", "2.1", page.getVersion());
    Assert.assertFalse("Document is hidden", page.isHidden());

    BaseClass baseClass = page.getXClass();
    Assert.assertNotNull(baseClass.getField("property"));
    Assert.assertEquals("property", baseClass.getField("property").getName());
    Assert.assertSame(NumberClass.class, baseClass.getField("property").getClass());

    // space.pagewithattachment

    XWikiDocument pagewithattachment = this.mockXWiki
            .getDocument(new DocumentReference("wiki", "space", "pagewithattachment"), getContext());
    Assert.assertFalse(pagewithattachment.isNew());
    Assert.assertEquals("Wrong version", "2.1", pagewithattachment.getVersion());
    Assert.assertEquals("Wrong creator", xarCreatorReference, pagewithattachment.getCreatorReference());
    Assert.assertEquals("Wrong author", xarAuthorReference, pagewithattachment.getAuthorReference());
    Assert.assertEquals("Wrong content author", xarContentAuthorReference,
            pagewithattachment.getContentAuthorReference());

    XWikiAttachment attachment = pagewithattachment.getAttachment("attachment.txt");
    Assert.assertNotNull(attachment);
    Assert.assertEquals("attachment.txt", attachment.getFilename());
    Assert.assertEquals(18, attachment.getContentSize(getContext()));
    Assert.assertEquals("attachment content", IOUtils.toString(attachment.getContentInputStream(getContext())));
    Assert.assertEquals("XWiki.attachmentauthor", attachment.getAuthor());

    // space1.page1

    XWikiDocument page1 = this.mockXWiki.getDocument(new DocumentReference("wiki", "space1", "page1"),
            getContext());

    Assert.assertFalse("Document wiki:space1.page1 has not been saved in the database", page1.isNew());

    // translated.translated
    DocumentReference translatedReference = new DocumentReference("wiki", "translated", "translated");
    XWikiDocument defaultTranslated = this.mockXWiki.getDocument(translatedReference, getContext());

    Assert.assertNotNull("Document wiki:translated.translated has not been saved in the database",
            defaultTranslated);
    Assert.assertFalse("Document wiki:translated.translated has not been saved in the database",
            defaultTranslated.isNew());

    Assert.assertEquals("Wrong content", "default content", defaultTranslated.getContent());
    Assert.assertEquals("Wrong creator", xarCreatorReference, defaultTranslated.getCreatorReference());
    Assert.assertEquals("Wrong author", xarAuthorReference, defaultTranslated.getAuthorReference());
    Assert.assertEquals("Wrong content author", xarContentAuthorReference,
            defaultTranslated.getContentAuthorReference());
    Assert.assertEquals("Wrong version", "1.1", defaultTranslated.getVersion());

    // translated.translated.tr
    XWikiDocument translated = this.documents.get(translatedReference).get("tr");

    Assert.assertNotNull(
            "Document wiki:translated.translated in langauge tr has not been saved in the database",
            translated);
    Assert.assertFalse("Document wiki:translated.translated in langauge tr has not been saved in the database",
            translated.isNew());

    Assert.assertEquals("Wrong content", "tr content", translated.getContent());
    Assert.assertEquals("Wrong creator", xarCreatorReference, translated.getCreatorReference());
    Assert.assertEquals("Wrong author", xarAuthorReference, translated.getAuthorReference());
    Assert.assertEquals("Wrong content author", xarContentAuthorReference,
            translated.getContentAuthorReference());
    Assert.assertEquals("Wrong version", "1.1", translated.getVersion());

    // translated.translated.fr
    XWikiDocument translated2 = this.documents.get(translatedReference).get("fr");

    Assert.assertNotNull(
            "Document wiki:translated.translated in language fr has not been saved in the database",
            translated2);
    Assert.assertFalse("Document wiki:translated.translated in langauge fr has not been saved in the database",
            translated2.isNew());

    Assert.assertEquals("Wrong content", "fr content", translated2.getContent());
    Assert.assertEquals("Wrong creator", xarCreatorReference, translated2.getCreatorReference());
    Assert.assertEquals("Wrong author", xarAuthorReference, translated2.getAuthorReference());
    Assert.assertEquals("Wrong content author", xarContentAuthorReference,
            translated2.getContentAuthorReference());
    Assert.assertEquals("Wrong version", "1.1", translated2.getVersion());

    // space.hiddenpage

    XWikiDocument hiddenpage = this.mockXWiki.getDocument(new DocumentReference("wiki", "space", "hiddenpage"),
            getContext());

    Assert.assertNotNull("Document wiki:space.hiddenpage has not been saved in the database", hiddenpage);
    Assert.assertFalse("Document wiki:space.hiddenpage has not been saved in the database", hiddenpage.isNew());

    Assert.assertTrue("Document is not hidden", hiddenpage.isHidden());
}

From source file:org.xwiki.extension.xar.XarExtensionHandlerTest.java

@Test
public void testUpgradeOnWiki() throws Throwable {
    getMockery().checking(new Expectations() {
        {/*  www. j  a  v a 2s .  co  m*/
            exactly(2).of(mockRightService).hasAccessLevel(with(equal("admin")),
                    with(equal("xwiki:XWiki.ExtensionUser")), with(equal("XWiki.XWikiPreferences")),
                    with(any(XWikiContext.class)));
            will(returnValue(true));
        }
    });

    install(this.localXarExtensiontId1, "wiki", this.contextUser);

    // upgrade

    install(this.localXarExtensiontId2, "wiki", this.contextUser);

    // validate

    // samespace.samepage

    XWikiDocument samepage = this.mockXWiki.getDocument(new DocumentReference("wiki", "samespace", "samepage"),
            getContext());

    Assert.assertEquals("Wrong versions", "1.1", samepage.getVersion());

    // space.page

    XWikiDocument modifiedpage = this.mockXWiki.getDocument(new DocumentReference("wiki", "space", "page"),
            getContext());

    Assert.assertFalse("Document wiki.space.page has not been saved in the database", modifiedpage.isNew());

    Assert.assertEquals("Wrong content", "content 2", modifiedpage.getContent());
    Assert.assertEquals("Wrong author", this.contextUser, modifiedpage.getAuthorReference());
    Assert.assertEquals("Wrong versions", "2.1", modifiedpage.getVersion());

    BaseClass baseClass = modifiedpage.getXClass();
    Assert.assertNotNull(baseClass.getField("property"));
    Assert.assertEquals("property", baseClass.getField("property").getName());
    Assert.assertSame(NumberClass.class, baseClass.getField("property").getClass());

    XWikiAttachment attachment = modifiedpage.getAttachment("attachment.txt");
    Assert.assertNotNull(attachment);
    Assert.assertEquals("attachment.txt", attachment.getFilename());
    Assert.assertEquals(18, attachment.getContentSize(getContext()));
    Assert.assertEquals("attachment content", IOUtils.toString(attachment.getContentInputStream(getContext())));

    // space2.page2

    XWikiDocument newPage = this.mockXWiki.getDocument(new DocumentReference("wiki", "space2", "page2"),
            getContext());

    Assert.assertFalse("Document wiki.space2.page2 has not been saved in the database", newPage.isNew());

    // space1.page1

    XWikiDocument removedPage = this.mockXWiki.getDocument(new DocumentReference("wiki", "space1", "page1"),
            getContext());

    Assert.assertTrue("Document wiki.space1.page1 has not been removed from the database", removedPage.isNew());
}