All Downloads are FREE. Search and download functionalities are using the official Maven repository.

at.spardat.enterprise.fmt.test.FmtTest Maven / Gradle / Ivy

There is a newer version: 6.0.2
Show newest version
/*******************************************************************************
 * Copyright (c) 2003, 2007 s IT Solutions AT Spardat GmbH .
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     s IT Solutions AT Spardat GmbH - initial API and implementation
 *******************************************************************************/

// @(#) $Id: FmtTest.java 3120 2009-02-11 10:44:52Z gub $
package at.spardat.enterprise.fmt.test;

import java.text.SimpleDateFormat;
import java.util.Locale;

import junit.framework.TestCase;
import at.spardat.enterprise.fmt.*;

/**
 * Testcase for fmt-package
 *
 * @author M. Schauer
 */
public class FmtTest extends TestCase {

    private String RES_BUNDLE = "at.spardat.enterprise.fmt.test.FmtTestErrors";

    public FmtTest(String name) {
        super(name);
    }

    private static Locale       deAT = new Locale ("de", "AT");

    private C[]             cases = new C[] {
        new C ("n,5,2,m&t", ABcdFmt.getInstance(5, 2, ABcdFmt.MANDATORY | ABcdFmt.THOUS_SEPS, deAT),    " ",         "err",      "" ),
        new C ("n,5,2,t", ABcdFmt.getInstance(5, 2, ABcdFmt.THOUS_SEPS, deAT),                        " ",          "",        "" ),
        new C ("n,5,2,t", ABcdFmt.getInstance(5, 2, ABcdFmt.THOUS_SEPS, deAT),                        "1123,0",     "1123.0", "1.123,00" ),
        new C ("n,5,2", ABcdFmt.getInstance(5, 2, ABcdFmt.NO_THOUS_SEPS, deAT),                     "1.123,0",    "1123.0", "1123,00" ),

        new C ("np,00000,5,2", ABcdFmt.getInstance("00000", -1, -1, ABcdFmt.DEFAULT, deAT),                       "1234",       "1234",   "01234"),
        new C ("np,##%,###.00,5,2", ABcdFmt.getInstance("##,###.00", 5, 2, ABcdFmt.DEFAULT, deAT),              "1.234",      "1234",   "1.234,00"),
        new C ("np,##%,###.00,5,2", ABcdFmt.getInstance("##,###.00", 5, 2, ABcdFmt.DEFAULT, deAT),              "111.234",    "err",   ""),
        new C ("np,00000,5,2", ABcdFmt.getInstance("00000", 5, 2, ABcdFmt.DEFAULT, deAT),              "0",    "0",   "00000"),

        new C ("nr,13,2,1,5,m", ABcdFmt.getInstance(13, 2, ABcdFmt.MANDATORY, 1, 5, deAT),                  "",           "err",     ""),
        new C ("nr,13,2,1,5,m", ABcdFmt.getInstance(13, 2, ABcdFmt.MANDATORY, 1, 5, deAT),                  "0",          "err",     ""),
        new C ("nr,13,2,1,5,m", ABcdFmt.getInstance(13, 2, ABcdFmt.MANDATORY, 1, 5, deAT),                  "1,0",        "1.0",     "1,00"),

        new C ("d,med&m", ADateFmt.getInstance(ADateFmt.MANDATORY|ADateFmt.MEDIUM, deAT),             " ",          "err",     ""),
        new C ("d", ADateFmt.getInstance(ADateFmt.MEDIUM, deAT),                                " ",          "",        ""),
        new C ("d,m", ADateFmt.getInstance(ADateFmt.MANDATORY|ADateFmt.MEDIUM, deAT),             "1.1.00",     "20000101","01.01.2000"),

        new C ("d,sho",   ADateFmt.getInstance(ADateFmt.SHORT, deAT),                           " ",          "",        ""),
        new C ("d,sho&m", ADateFmt.getInstance(ADateFmt.MANDATORY|ADateFmt.SHORT, deAT),        " ",          "err",     ""),
        new C ("d,sho&m", ADateFmt.getInstance(ADateFmt.MANDATORY|ADateFmt.SHORT, deAT),        "1.1.1987",   "19870101","01.01.87"),

        new C ("dp,ddMMyyyy", ADateFmt.getInstance("ddMMyyyy"),                                "abcdefg",    "err",     ""),
        new C ("dp,ddMMyyyy", ADateFmt.getInstance("ddMMyyyy"),                                "10111966x",  "err",     ""),
        new C ("dp,ddMMyyyy", ADateFmt.getInstance("ddMMyyyy"),                                "x10111966",  "err",     ""),
        new C ("dp,ddMMyyyy", ADateFmt.getInstance("ddMMyyyy"),                                "10111966" ,  "19661110",     "10111966"),

        new C ("s,10", AStringFmt.getInstance(10),                                                 "",           "",        ""),
        new C ("s,10,m", AStringFmt.getInstance(10, AStringFmt.MANDATORY),                           "",           "err",     ""),
        new C ("s,10,m", AStringFmt.getInstance(10, AStringFmt.MANDATORY),                           "ab ",        "ab ",     "ab "),

        new C ("sr,,5,a-c,m", AStringFmt.getInstance(5, "a-c", AStringFmt.MANDATORY),                     "",           "err",     ""),
        new C ("sr,,5,a-c,m", AStringFmt.getInstance(5, "a-c", AStringFmt.MANDATORY),                     "ad",         "err",     ""),
        new C ("sr,,5,a-c,m", AStringFmt.getInstance(5, "a-c", AStringFmt.MANDATORY),                     "abcabc",     "err",     ""),
        new C ("sr,,5,a-c,m", AStringFmt.getInstance(5, "a-c", AStringFmt.MANDATORY),                     "abc",        "abc",     "abc"),
        new C ("sr,,5,a-c", AStringFmt.getInstance(5, "a-c"),                                           "",           "",        ""),

////////////AStringFmtRangeRegEx Cases
        //ok - with range
        new C ("sre,,15,a-e@.,m,NoEmail,at.spardat.enterprise.fmt.test.FmtTestErrors,\\w+(\\.\\w+)*@\\w+\\.\\w+", AStringFmt.getInstance(15, "a-e@.", AStringFmt.MANDATORY,"\\w+(\\.\\w+)*@\\w+\\.\\w+","NoEmail",RES_BUNDLE), "[email protected]", "[email protected]","[email protected]"),
//      //ok - without range
        new C ("sre,,15,,m,NoEmail,at.spardat.enterprise.fmt.test.FmtTestErrors,\\w+(\\.\\w+)*@\\w+\\.\\w+", AStringFmt.getInstance(15, "", AStringFmt.MANDATORY,"\\w+(\\.\\w+)*@\\w+\\.\\w+","NoEmail",RES_BUNDLE), "[email protected]", "[email protected]","[email protected]"),
        //ok - toUpper
        new C ("sre,,15,a-e@.,m&uc,NoEmail,at.spardat.enterprise.fmt.test.FmtTestErrors,\\w+(\\.\\w+)*@\\w+\\.\\w+", AStringFmt.getInstance(15, "a-e@.", AStringFmt.MANDATORY | AStringFmt.UPPER_CASE,"\\w+(\\.\\w+)*@\\w+\\.\\w+","NoEmail",RES_BUNDLE), "[email protected]", "[email protected]","[email protected]"),
        //too long
        new C ("sre,,1,,m,NoEmail,at.spardat.enterprise.fmt.test.FmtTestErrors,\\w+(\\.\\w+)*@\\w+\\.\\w+", AStringFmt.getInstance(1, "", AStringFmt.MANDATORY,"\\w+(\\.\\w+)*@\\w+\\.\\w+","NoEmail",RES_BUNDLE), "[email protected]", "err","[email protected]"),
//      range not valid
        new C ("sre,,15,a-e,m,NoEmail,at.spardat.enterprise.fmt.test.FmtTestErrors,\\w+(\\.\\w+)*@\\w+\\.\\w+", AStringFmt.getInstance(15, "a-e", AStringFmt.MANDATORY,"\\w+(\\.\\w+)*@\\w+\\.\\w+","NoEmail",RES_BUNDLE), "[email protected]", "err","[email protected]"),
        //pattern not valid
        new C ("sre,,15,a-e@.,m,NoEmail,at.spardat.enterprise.fmt.test.FmtTestErrors,\\w+(\\.\\w+)*@\\w+\\.\\w+", AStringFmt.getInstance(15, "a-e@.", AStringFmt.MANDATORY,"\\w+(\\.\\w+)*@\\w+\\.\\w+","NoEmail",RES_BUNDLE), "abcde.abc.ab", "err","abcde.abc.ab"),
//      range & pattern not valid
        new C ("sre,,15,a-e@,m,NoEmail,at.spardat.enterprise.fmt.test.FmtTestErrors,\\w+(\\.\\w+)*@\\w+\\.\\w+", AStringFmt.getInstance(15, "a-e@", AStringFmt.MANDATORY,"\\w+(\\.\\w+)*@\\w+\\.\\w+","NoEmail",RES_BUNDLE), "abcde.abc.ab", "err","abcde.abc.ab"),
//      error empty input
        new C ("sre,,15,a-e@,m,NoEmail,at.spardat.enterprise.fmt.test.FmtTestErrors,\\w+(\\.\\w+)*@\\w+\\.\\w+", AStringFmt.getInstance(15, "a-e@", AStringFmt.MANDATORY,"\\w+(\\.\\w+)*@\\w+\\.\\w+","NoEmail",RES_BUNDLE), "", "err",""),

        new C ("ts,med&m,med", ATimeStampFmt.getInstance(ATimeStampFmt.MEDIUM|ATimeStampFmt.MANDATORY, ATimeStampFmt.MEDIUM, deAT), "", "err", ""),
        new C ("ts", ATimeStampFmt.getInstance(ATimeStampFmt.MEDIUM, ATimeStampFmt.MEDIUM, deAT), " ", "", ""),
        new C ("ts,m", ATimeStampFmt.getInstance(ATimeStampFmt.MEDIUM|ATimeStampFmt.MANDATORY, ATimeStampFmt.MEDIUM, deAT), "1.1.2000 13:47:24", "946730844 0", "01.01.2000 13:47:24"),
        new C ("tsp,dd.MM.yyyy HH:mm:ss.SSS zz", ATimeStampFmt.getInstance ("dd.MM.yyyy HH:mm:ss.SSS zz", deAT),             "28.02.1969 10:45:57.002 CET", "-26489643 2000000", "28.02.1969 10:45:57.002 CET"),

        new C ("b", ABooleanFmt.getInstance(IFmt.DEFAULT, deAT), "ja", "J", "ja"),
        new C ("b,lon", ABooleanFmt.getInstance(ABooleanFmt.LONG, deAT), "nein", "N", "nein"),
        new C ("b,sho", ABooleanFmt.getInstance(ABooleanFmt.SHORT, deAT), "J", "J", "J"),
        new C ("b,m&sho", ABooleanFmt.getInstance(ABooleanFmt.MANDATORY|ABooleanFmt.SHORT, deAT), "N", "N", "N"),

    };


    public void testFmt () throws Exception {
        for (int i=0; i




© 2015 - 2024 Weber Informatics LLC | Privacy Policy