⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 trombinoscopegeneratortest.java

📁 OPIAM stands for Open Identity and Access Management. This Suite will provide modules for user & rig
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
            args.add(arg);

            SearchResult begEntries = StandardService.search(args, _ADMINCONTEXT);

            if (begEntries != null)
            {
                List entries = begEntries.getLResults();

                if (entries.size() > 0)
                {
                    // Gets the attributes list
                    ArrayList attrs = new ArrayList();

                    for (int i = 0; i < attrsList.length; i++)
                    {
                        attrs.add(attrsList[i]);
                    }

                    // generates a trombinoscope with 2 columns, and 6 entries,*
                    // and the first result of the search is not included.
                    // result : 8 entries, 2 columns
                    ByteArrayOutputStream baos = null;

                    _test.displayMsg("Number of entries : " + entries.size());

                    _test.displayMsg(TestUtils.NEXT +
                        "Parameters = StartIndex : -1, NbColumns : 2, NbEntries : 6");

                    try
                    {
                        baos = TrombinoscopeGenerator.generatePdfTrombinoscope(-1,
                                2, 6, entries, attrs);
                        testPdfTromb(baos);
                    }
                    catch (ServiceException serex)
                    {
                        _test.displayResultSuccess("Error handled");
                    }
                    catch (Exception ex)
                    {
                        _test.displayResultFailure(ex.toString());
                    }

                    _test.displayMsg(TestUtils.NEXT +
                        "Parameters = StartIndex : 100, NbColumns : 2, NbEntries : 6");

                    try
                    {
                        baos = TrombinoscopeGenerator.generatePdfTrombinoscope(100,
                                2, 6, entries, attrs);
                        testPdfTromb(baos);
                    }
                    catch (ServiceException serex)
                    {
                        _test.displayResultSuccess("Error handled");
                    }
                    catch (Exception ex)
                    {
                        _test.displayResultFailure(ex.toString());
                    }

                    _test.displayMsg(TestUtils.NEXT +
                        "Parameters = StartIndex : 1, NbColumns : 2, NbEntries : -1");

                    try
                    {
                        baos = TrombinoscopeGenerator.generatePdfTrombinoscope(1,
                                2, -1, entries, attrs);
                        testPdfTromb(baos);
                    }
                    catch (ServiceException serex)
                    {
                        _test.displayResultSuccess("Error handled");
                    }
                    catch (Exception ex)
                    {
                        _test.displayResultFailure(ex.toString());
                    }

                    _test.displayMsg(TestUtils.NEXT +
                        "Parameters = StartIndex : 1, NbColumns : 2, NbEntries : 20");

                    try
                    {
                        baos = TrombinoscopeGenerator.generatePdfTrombinoscope(1,
                                2, 20, entries, attrs);
                        testPdfTromb2(baos);
                    }
                    catch (ServiceException serex)
                    {
                        _test.displayResultSuccess("Error handled");
                    }
                    catch (Exception ex)
                    {
                        _test.displayResultFailure(ex.toString());
                    }

                    _test.displayMsg(TestUtils.NEXT +
                        "Parameters = StartIndex : 1, NbColumns : 2, NbEntries : 0");

                    try
                    {
                        baos = TrombinoscopeGenerator.generatePdfTrombinoscope(1,
                                2, 0, entries, attrs);
                        testPdfTromb(baos);
                    }
                    catch (ServiceException serex)
                    {
                        _test.displayResultSuccess("Error handled");
                    }
                    catch (Exception ex)
                    {
                        _test.displayResultFailure(ex.toString());
                    }

                    _test.displayMsg(TestUtils.NEXT +
                        "Parameters = StartIndex : 1, NbColumns : 0, NbEntries : 6");

                    try
                    {
                        baos = TrombinoscopeGenerator.generatePdfTrombinoscope(1,
                                0, 6, entries, attrs);
                        testPdfTromb(baos);
                    }
                    catch (ServiceException serex)
                    {
                        _test.displayResultSuccess("Error handled");
                    }
                    catch (Exception ex)
                    {
                        _test.displayResultFailure(ex.toString());
                    }

                    _test.displayMsg(TestUtils.NEXT +
                        "Parameters = StartIndex : 1, NbColumns : -1, NbEntries : 6");

                    try
                    {
                        baos = TrombinoscopeGenerator.generatePdfTrombinoscope(1,
                                -1, 6, entries, attrs);
                        testPdfTromb(baos);
                    }
                    catch (ServiceException serex)
                    {
                        _test.displayResultSuccess("Error handled");
                    }
                    catch (Exception ex)
                    {
                        _test.displayResultFailure(ex.toString());
                    }

                    _test.displayMsg(TestUtils.NEXT +
                        "Parameters = StartIndex : 1, NbColumns : 10, NbEntries : 6");

                    try
                    {
                        baos = TrombinoscopeGenerator.generatePdfTrombinoscope(1,
                                10, 6, entries, attrs);
                        testPdfTromb3(baos);
                    }
                    catch (ServiceException serex)
                    {
                        _test.displayResultSuccess("Error handled");
                    }
                    catch (Exception ex)
                    {
                        _test.displayResultFailure(ex.toString());
                    }

                    _test.displayMsg(TestUtils.NEXT +
                        "Parameters = Attributes : null");

                    try
                    {
                        baos = TrombinoscopeGenerator.generatePdfTrombinoscope(1,
                                2, 6, entries, null);
                        testPdfTromb(baos);
                    }
                    catch (ServiceException serex)
                    {
                        _test.displayResultSuccess("Error handled");
                    }
                    catch (Exception ex)
                    {
                        _test.displayResultFailure(ex.toString());
                    }

                    _test.displayMsg(TestUtils.NEXT +
                        "Parameters = Entries : null");

                    try
                    {
                        baos = TrombinoscopeGenerator.generatePdfTrombinoscope(1,
                                2, 6, null, attrs);
                        testPdfTromb(baos);
                    }
                    catch (ServiceException serex)
                    {
                        _test.displayResultSuccess("Error handled");
                    }
                    catch (Exception ex)
                    {
                        _test.displayResultFailure(ex.toString());
                    }
                }
                else
                {
                    _test.displayResultFailure("No entries");
                }
            }
            else
            {
                _test.displayResultFailure("SearchResult = null");
            }
        }
        catch (Exception ex)
        {
            StringBuffer msg = new StringBuffer();
            msg.append("Exception : ");
            msg.append(TestUtils.NEXT);
            msg.append(ex.toString());
            _test.displayResultError(msg.toString());
        }

        _test.displayFooterMethod("testGeneratePdfTrombinoscopeError");
    }

    /**
     * Checks if the size of the generated PDF is equal to the reference PDF.
     *
     * @param name  Name of the reference PDF file.
     * @param baos  The generated PDF.
     */
    private static void testPdfTrombX(String name, ByteArrayOutputStream baos)
    {
        if (baos != null)
        {
            // allows to create the reference pdf file for the following tests.
            //_test.createFile(name, PDF_PATH, baos.toByteArray());
            //_test.displayMsg("Number of entries : " + entries.size());
            //_test.displayMsg("First entries : " + ((JBTop)entries.get(0)).getDn());
            // Gets the reference pdf file.
            byte[] refPdf = _test.readBytesFromFile(name, PDF_PATH);
            _test.displayMsg("Size of the generated PDF : " + baos.size());
            _test.displayMsg("Size of the reference PDF : " + refPdf.length);

            if (baos.size() == refPdf.length)
            {
                _test.displayResultSuccess(null);
            }
            else
            {
                _test.displayResultFailure(null);
            }
        }
        else
        {
            _test.displayResultFailure("No trombinoscope generated");
        }
    }

    /**
     * Checks if the size of the generated PDF is equal to the reference PDF.
     *
     * @param baos  The generated PDF.
     */
    private static void testPdfTromb(ByteArrayOutputStream baos)
    {
        testPdfTrombX(PDF_NAME, baos);
    }

    /**
     * Checks if the size of the generated PDF is equal to the reference PDF.
     *
     * @param baos  The generated PDF.
     */
    private static void testPdfTromb2(ByteArrayOutputStream baos)
    {
        testPdfTrombX(PDF_NAME2, baos);
    }

    /**
     * Checks if the size of the generated PDF is equal to the reference PDF.
     *
     * @param baos  The generated PDF.
     */
    private static void testPdfTromb3(ByteArrayOutputStream baos)
    {
        testPdfTrombX(PDF_NAME3, baos);
    }

    /**
     * Checks if the size of the generated image is equal to the reference image.
     *
     * @param startIndex  Starting index.
     * @param nbCols   Number of columns.
     * @param nbEntries  Number of entries.
     * @param entries  List of the entries.
     * @param attributes  List of the attributes.
     * @param imageType  Type of the image.
     */
    private static void testImageTromb(int startIndex, int nbCols,
        int nbEntries, List entries, ArrayList attributes, String imageType)
    {
        _test.displayMsg("Trombi Image type : " + imageType);

        List tromb = null;
        try
        {
            tromb = TrombinoscopeGenerator.generateTrombinoscope(startIndex,
                nbCols, nbEntries, entries, attributes, imageType);
        }
        catch (Exception ex)
        {
            _test.displayResultFailure(ex.toString());
        }

        if (tromb != null)
        {
            ByteArrayOutputStream baos = (ByteArrayOutputStream) tromb.get(0);

            // allows to create the reference image file for the following tests.
            //_test.createFile(IMAGE_NAME + imageType, IMAGE_PATH, baos.toByteArray());
            //_test.displayMsg("Number of entries : " + entries.size());
            //_test.displayMsg("First entries : " + ((JBTop)entries.get(0)).getDn());
            // Gets the reference image file.
            byte[] refImage = _test.readBytesFromFile(IMAGE_NAME + imageType,
                    IMAGE_PATH);
            _test.displayMsg("Size of the generated image : " + baos.size());
            _test.displayMsg("Size of the reference image : " +
                refImage.length);

            if (baos.size() == refImage.length)
            {
                _test.displayResultSuccess(null);
            }
            else
            {
                _test.displayResultFailure(null);
            }
        }
        else
        {
            _test.displayResultFailure("No trombinoscope generated");
        }
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -