Package util

Source Code of util.PrioritizedMsg

/*
* This file is part of the WfMOpen project.
* Copyright (C) 2001-2003 Danet GmbH (www.danet.de), GS-AN.
* All rights reserved.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
*
* $Id: PrioritizedMsg.java 1607 2006-09-29 12:32:13Z drmlipp $
*
* $Log$
* Revision 1.1.1.2  2003/08/26 13:23:25  drmlipp
* Update to 1.0rc2
*
* Revision 1.4  2003/08/25 13:57:26  lipp
* Fixed test.
*
* Revision 1.3  2003/06/27 09:44:13  lipp
* Fixed copyright/license information.
*
* Revision 1.2  2003/03/31 16:50:29  huaiyang
* Logging using common-logging.
*
* Revision 1.1  2003/03/07 10:31:40  huaiyang
* Moved from the directory of api.
*
* Revision 1.3  2003/03/07 09:35:21  huaiyang
* Changed because of the new ImportMessage.properties.
*
* Revision 1.2  2003/03/07 08:02:24  huaiyang
* add the test for Locale.ENGLISH and Locale.GERMAN.
*
* Revision 1.1  2003/03/05 14:36:46  huaiyang
* Initial.
*
*
*
*/
package util;

import java.util.Locale;

import de.danet.an.workflow.api.PrioritizedMessage;

import junit.framework.Test;
import junit.framework.TestSuite;
import junit.framework.TestCase;

/**
* Test the functionality of the class
* <code>de.danet.an.workflow.api.PrioritizedMessage</code>.
*/
public class PrioritizedMsg extends TestCase {

    /** logger of this class */
    static final org.apache.commons.logging.Log logger
  = org.apache.commons.logging.LogFactory.getLog(PrioritizedMsg.class);

    /**
     * Constructor of this TestCase
     *
     * @param name name of this test case.
     */
    public PrioritizedMsg(String name) {
  super (name);
    }

    /**
     * build this testsuite.
     * @return the constructed test suite.
     */
    public static Test suite() {
        TestSuite suite = new TestSuite();
     suite.addTest(new PrioritizedMsg("message"));
     suite.addTest(new PrioritizedMsg("messageInEnglish"));
     suite.addTest(new PrioritizedMsg("messageInGerman"));
        return suite;
    }

    /**
     * construct a prioritized message with a message that does not have
     * the format "<code>a.resource.bundle.base.name#key</code>", then check
     * the return value of the method <code>message()</code>.
     */
    public void message() {
  String testMsg = "test message without key";
  PrioritizedMessage pm = new PrioritizedMessage
      (PrioritizedMessage.Priority.WARN, testMsg);
  assertTrue(pm.message().equals(testMsg));
    }
 
    /**
     * construct a prioritized message with a message that does have
     * the format "<code>a.resource.bundle.base.name#key</code>", then check
     * the return value of the method <code>message(Locale.ENGLISH)</code>.
     */
    public void messageInEnglish() {
  // get the default locale
  Locale defaultLocale = Locale.getDefault();
  Locale.setDefault(Locale.CHINESE);
  String testMsg = "OTHERWISE-transition not at the end of "
      + "TransitionRestrictions (will be ignored!)";
  assertTrue
      (getMessageWithKey(Locale.ENGLISH).equals(testMsg));
  String atestMsg = "Process testProcess is not unique";
  logger.debug("set Locale default: " + Locale.getDefault());
  assertTrue
      (getMessageWithKeyAndObjects(Locale.ENGLISH).equals(atestMsg));
  Locale.setDefault(defaultLocale);
  logger.debug("restore Locale default: " + Locale.getDefault());
    }

    /**
     * construct a prioritized message with a message that does have
     * the format "<code>a.resource.bundle.base.name#key</code>", then check
     * the return value of the method <code>message(Locale.GERMAN)</code>.
     */
    public void messageInGerman() {
  String testMsg = "OTHERWISE-Transition nicht am Ende von "
      + "TransitionRestrictions, sie wird ignoriert!";
  assertTrue
      (getMessageWithKey(Locale.GERMAN).equals(testMsg));
  String atestMsg = "Prozess testProcess ist nicht eindeutig";
  assertTrue
      (getMessageWithKeyAndObjects(Locale.GERMAN).equals(atestMsg));
    }

    private String getMessageWithKey(Locale locale) {
  PrioritizedMessage pm = new PrioritizedMessage
      (PrioritizedMessage.Priority.ERROR,
       "ImportMessages#procdef.transition.otherwise.notatend");
  String internationizedMsg = pm.message(locale);
  logger.debug("internationized message: " + internationizedMsg);
  return internationizedMsg;
    }

    private String getMessageWithKeyAndObjects(Locale locale) {
  Object[] objects = {"testProcess"};
  PrioritizedMessage pm = new PrioritizedMessage
      (PrioritizedMessage.Priority.ERROR,
       "ImportMessages#procdef.process.ununique", objects);
  String internationizedMsg = pm.message(locale);
  logger.debug("internationized message: " + internationizedMsg);
  return internationizedMsg;
    }

}
TOP

Related Classes of util.PrioritizedMsg

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.