2713N/A/*
2713N/A * CDDL HEADER START
2713N/A *
2713N/A * The contents of this file are subject to the terms of the
2713N/A * Common Development and Distribution License, Version 1.0 only
2713N/A * (the "License"). You may not use this file except in compliance
2713N/A * with the License.
2713N/A *
2713N/A * You can obtain a copy of the license at
2713N/A * trunk/opends/resource/legal-notices/OpenDS.LICENSE
2713N/A * or https://OpenDS.dev.java.net/OpenDS.LICENSE.
2713N/A * See the License for the specific language governing permissions
2713N/A * and limitations under the License.
2713N/A *
2713N/A * When distributing Covered Code, include this CDDL HEADER in each
2713N/A * file and include the License file at
2713N/A * trunk/opends/resource/legal-notices/OpenDS.LICENSE. If applicable,
2713N/A * add the following below this CDDL HEADER, with the fields enclosed
2713N/A * by brackets "[]" replaced with your own identifying information:
2713N/A * Portions Copyright [yyyy] [name of copyright owner]
2713N/A *
2713N/A * CDDL HEADER END
2713N/A *
2713N/A *
3232N/A * Copyright 2007-2008 Sun Microsystems, Inc.
2713N/A */
2713N/A
2713N/Apackage org.opends.messages;
2713N/A
2713N/Aimport static org.testng.Assert.*;
2713N/Aimport org.testng.annotations.BeforeClass;
2713N/Aimport org.testng.annotations.DataProvider;
2713N/Aimport org.testng.annotations.Test;
2713N/A
2713N/Aimport java.io.IOException;
2713N/Aimport java.util.Locale;
2713N/A
2713N/A/**
2713N/A * Message Tester.
2713N/A */
2713N/Apublic class MessageBuilderTest extends MessagesTestCase {
2713N/A
2713N/A @BeforeClass
2713N/A public void setUp() throws IOException {
2713N/A createDummyLocalizedCoreMessagesFile();
2713N/A }
2713N/A
2713N/A
2713N/A @DataProvider(name = "toMessageData")
2713N/A public Object[][] toMessageData() {
2713N/A return new Object[][]{
2713N/A
2713N/A // All strings
2713N/A { new CharSequence[] {
2713N/A "Once", " upon", " a", " time." },
2713N/A "Once upon a time." },
2713N/A
2713N/A // All messages
2713N/A { new CharSequence[] {
2713N/A Message.raw("Once"),
2713N/A Message.raw(" upon"),
2713N/A Message.raw(" a"),
2713N/A Message.raw(" time.") },
2713N/A "Once upon a time." },
2713N/A
2713N/A // Mix of strings and messages
2713N/A { new CharSequence[] {
2713N/A Message.raw("Once"),
2713N/A " upon",
2713N/A Message.raw(" a"),
2713N/A " time." },
2713N/A "Once upon a time." },
2713N/A
2729N/A // Lots of messages
2729N/A { new CharSequence[] {
2729N/A Message.raw("North"),
2729N/A Message.raw(" America"),
2729N/A Message.raw(" is"),
2729N/A Message.raw(" divided"),
2729N/A Message.raw(" into"),
2729N/A Message.raw(" two"),
2729N/A Message.raw(" vast"),
2729N/A Message.raw(" regions,"),
2729N/A Message.raw(" one"),
2729N/A Message.raw(" inclining"),
2729N/A Message.raw(" towards"),
2729N/A Message.raw(" the"),
2729N/A Message.raw(" Pole,"),
2729N/A Message.raw(" the"),
2729N/A Message.raw(" other"),
2729N/A Message.raw(" towards"),
2729N/A Message.raw(" the"),
2729N/A Message.raw(" Equator--Valley"),
2729N/A Message.raw(" of"),
2729N/A Message.raw(" the"),
2729N/A Message.raw(" Mississippi--Traces"),
2729N/A Message.raw(" found"),
2729N/A Message.raw(" there"),
2729N/A Message.raw(" of"),
2729N/A Message.raw(" the"),
2729N/A Message.raw(" revolutions"),
2729N/A Message.raw(" of"),
2729N/A Message.raw(" the"),
2729N/A Message.raw(" globe"),
2729N/A Message.raw(" --Shore"),
2729N/A Message.raw(" of"),
2729N/A Message.raw(" the"),
2729N/A Message.raw(" Atlantic"),
2729N/A Message.raw(" Ocean,"),
2729N/A Message.raw(" on"),
2729N/A Message.raw(" which"),
2729N/A Message.raw(" the"),
2729N/A Message.raw(" English"),
2729N/A Message.raw(" colonies"),
2729N/A Message.raw(" were"),
2729N/A Message.raw(" founded--Different"),
2729N/A Message.raw(" aspects"),
2729N/A Message.raw(" of"),
2729N/A Message.raw(" North"),
2729N/A Message.raw(" and"),
2729N/A Message.raw(" of"),
2729N/A Message.raw(" South"),
2729N/A Message.raw(" America"),
2729N/A Message.raw(" at"),
2729N/A Message.raw(" the"),
2729N/A Message.raw(" time"),
2729N/A Message.raw(" of"),
2729N/A Message.raw(" their"),
2729N/A Message.raw(" discovery--Forests"),
2729N/A Message.raw(" of"),
2729N/A Message.raw(" North"),
2729N/A Message.raw(" America"),
2729N/A Message.raw(" --Prairies--Wandering"),
2729N/A Message.raw(" tribes"),
2729N/A Message.raw(" of"),
2729N/A Message.raw(" natives--Their"),
2729N/A Message.raw(" outward"),
2729N/A Message.raw(" appearance,"),
2729N/A Message.raw(" customs,"),
2729N/A Message.raw(" and"),
2729N/A Message.raw(" languages--Traces"),
2729N/A Message.raw(" of"),
2729N/A Message.raw(" an"),
2729N/A Message.raw(" unknown"),
2729N/A Message.raw(" people.") },
2729N/A "North America is divided into two vast regions, one inclining towards the Pole," +
2729N/A " the other towards the Equator--Valley of the Mississippi--Traces found there of" +
2729N/A " the revolutions of the globe --Shore of the Atlantic Ocean, on which the English" +
2729N/A " colonies were founded--Different aspects of North and of South America at the" +
2729N/A " time of their discovery--Forests of North America --Prairies--Wandering tribes" +
2729N/A " of natives--Their outward appearance, customs, and languages--Traces of an" +
2729N/A " unknown people."
2729N/A }
2729N/A
2713N/A };
2713N/A }
2713N/A
2713N/A @Test (dataProvider = "toMessageData")
2713N/A public void testToMessage(CharSequence[] content, String result)
2713N/A {
2713N/A MessageBuilder mb = new MessageBuilder();
2713N/A for (CharSequence c : content) {
2713N/A mb.append(c);
2713N/A }
2713N/A Message m = mb.toMessage();
2713N/A assertTrue(result.equals(m.toString()));
2713N/A }
2713N/A
2713N/A
2713N/A @DataProvider(name = "toMessageData1")
2713N/A public Object[][] toMessageData1() {
2713N/A return new Object[][]{
2713N/A
2713N/A // default locale
2713N/A { new CharSequence[] {
2713N/A CoreMessages.ERR_ADD_CANNOT_ADD_ROOT_DSE.get(),
2713N/A CoreMessages.ERR_ABANDON_OP_NO_SUCH_OPERATION.get(1) },
2713N/A Locale.getDefault(),
2713N/A CoreMessages.ERR_ADD_CANNOT_ADD_ROOT_DSE.get().toString() +
2713N/A CoreMessages.ERR_ABANDON_OP_NO_SUCH_OPERATION.get(1).toString() },
2713N/A
2713N/A { new CharSequence[] {
2713N/A CoreMessages.ERR_ADD_CANNOT_ADD_ROOT_DSE.get(),
2713N/A CoreMessages.ERR_ABANDON_OP_NO_SUCH_OPERATION.get(1) },
2713N/A TEST_LOCALE,
2713N/A CoreMessages.ERR_ADD_CANNOT_ADD_ROOT_DSE.get().toString(TEST_LOCALE) +
2713N/A CoreMessages.ERR_ABANDON_OP_NO_SUCH_OPERATION.get(1).toString(TEST_LOCALE) }
2713N/A
2713N/A };
2713N/A }
2713N/A
2713N/A
2713N/A @Test (dataProvider = "toMessageData1")
2713N/A public void testToMessage1(CharSequence[] content, Locale locale, String result)
2713N/A {
2713N/A MessageBuilder mb = new MessageBuilder();
2713N/A for (CharSequence c : content) {
2713N/A mb.append(c);
2713N/A }
2713N/A Message m = mb.toMessage();
2713N/A assertTrue(result.equals(m.toString(locale)));
2713N/A }
2713N/A
3076N/A
3076N/A
3076N/A @DataProvider(name = "toMessageData2")
3076N/A public Object[][] toMessageData2() {
3076N/A return new Object[][] {
3076N/A {
3076N/A CoreMessages.ERR_ADD_CANNOT_ADD_ROOT_DSE.get(),
3076N/A CoreMessages.ERR_ABANDON_OP_NO_SUCH_OPERATION.get(1),
3076N/A CoreMessages.ERR_ADD_CANNOT_ADD_ROOT_DSE.getCategory(),
3076N/A CoreMessages.ERR_ADD_CANNOT_ADD_ROOT_DSE.getSeverity()
3076N/A },
3076N/A {
3076N/A Message.raw(Category.JEB, Severity.FATAL_ERROR, "test message"),
3076N/A CoreMessages.ERR_ABANDON_OP_NO_SUCH_OPERATION.get(1),
3076N/A Category.JEB,
3076N/A Severity.FATAL_ERROR
3076N/A },
3076N/A {
3076N/A Message.raw("test message"),
3076N/A CoreMessages.ERR_ABANDON_OP_NO_SUCH_OPERATION.get(1),
3076N/A Category.USER_DEFINED,
3076N/A Severity.INFORMATION
3076N/A }
3076N/A };
3076N/A }
3076N/A
3076N/A
3076N/A
3076N/A @Test(dataProvider = "toMessageData2")
3076N/A public void testToMessage2(Message m1, Message m2, Category c, Severity s) {
3076N/A MessageBuilder mb = new MessageBuilder();
3076N/A
3076N/A mb.append(m1);
3076N/A mb.append(m2);
3076N/A Message m = mb.toMessage();
3076N/A
3076N/A assertEquals(m.getDescriptor().getCategory(), c);
3076N/A assertEquals(m.getDescriptor().getSeverity(), s);
3076N/A }
2713N/A}