//
// This file is part of the OpenNMS(R) Application.
//
// OpenNMS(R) is Copyright (C) 2006 The OpenNMS Group, Inc.  All rights reserved.
// OpenNMS(R) is a derivative work, containing both original code, included code and modified
// code that was published under the GNU General Public License. Copyrights for modified
// and included code are below.
//
// OpenNMS(R) is a registered trademark of The OpenNMS Group, Inc.
//
// Original code base Copyright (C) 1999-2001 Oculan Corp.  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.
//
// For more information contact:
//      OpenNMS Licensing       <license@opennms.org>
//      http://www.opennms.org/
//      http://www.opennms.com/
//
package org.opennms.netmgt.dao.db;

import java.io.ByteArrayOutputStream;
import java.io.PrintStream;

public class PopulatedTemporaryDatabaseTestCase extends
        TemporaryDatabaseTestCase {
    
    private InstallerDb m_installerDb;
    
    private ByteArrayOutputStream m_outputStream;
    
    protected void setUp() throws Exception {
        super.setUp();
        
        initializeDatabase();
    }

    protected void initializeDatabase() throws Exception {
        if (!isEnabled()) {
            return;
        }
        
        m_installerDb = new InstallerDb();

        // Create a ByteArrayOutputSteam to effectively throw away output.
        resetOutputStream();
        m_installerDb.setDatabaseName(getTestDatabase());
        m_installerDb.setDataSource(getDataSource());
        
        m_installerDb.setCreateSqlLocation(
            "../opennms-daemon/src/main/filtered/etc/create.sql");

        m_installerDb.setStoredProcedureDirectory(
            "../opennms-daemon/src/main/filtered/etc");

        //installerDb.setDebug(true);

        m_installerDb.readTables();
        
        m_installerDb.createSequences();
        m_installerDb.updatePlPgsql();
        m_installerDb.addStoredProcedures();
        
        m_installerDb.createTables();

        m_installerDb.closeConnection();
    }

    public ByteArrayOutputStream getOutputStream() {
        return m_outputStream;
    }
    
    public void resetOutputStream() {
        m_outputStream = new ByteArrayOutputStream();
        m_installerDb.setOutputStream(new PrintStream(m_outputStream));
    }
}

@@ -1450,16 +1450,64 @@
 Stream;%0A
+import java.io.File;%0Aimport java.io.FileFilter;%0A
 import j
@@ -1713,24 +1713,68 @@
 utputStream;
+%0A%0A    private boolean m_setupIpLike = false;
 %0A    %0A    pr
@@ -2727,78 +2727,1455 @@
     
-m_installerDb.createTables();%0A%0A        m_installerDb.closeConnection()
+if (m_setupIpLike) %7B%0A            m_installerDb.setPgIpLikeLocation(findIpLikeLibrary().getAbsolutePath());%0A            m_installerDb.updateIplike();%0A        %7D%0A%0A        m_installerDb.createTables();%0A%0A        m_installerDb.closeConnection();%0A    %7D%0A%0A    private File findIpLikeLibrary() %7B%0A        File topTargetDir = new File(%22../target%22);%0A        assertTrue(%22top-level target directory exists at ../target%22, topTargetDir.exists());%0A        %0A        File%5B%5D distDirs = topTargetDir.listFiles(new FileFilter() %7B%0A            public boolean accept(File file) %7B%0A                if (file.getName().matches(%22opennms-%5C%5Cd.*%22) && file.isDirectory()) %7B%0A                    return true;%0A                %7D else %7B%0A                    return false;%0A                %7D%0A            %7D%0A        %7D);%0A        assertEquals(%22expecting exactly one opennms distribution directory%22, 1, distDirs.length);%0A        %0A        File libDir = new File(distDirs%5B0%5D, %22lib%22);%0A        assertTrue(%22lib directory exists%22, libDir.isDirectory());%0A%0A        File%5B%5D iplikeFiles = libDir.listFiles(new FileFilter() %7B%0A            public boolean accept(File file) %7B%0A                if (file.getName().matches(%22iplike%5C%5C..*%22) && file.isFile()) %7B%0A                    return true;%0A                %7D else %7B%0A                    return false;%0A                %7D%0A            %7D%0A        %7D);%0A        assertEquals(%22expecting exactly one iplike file%22, 1, iplikeFiles.length);%0A        %0A        return iplikeFiles%5B0%5D
 ;%0A  
@@ -4444,10 +4444,112 @@
 ;%0A    %7D%0A
+    %0A    public void setSetupIpLike(boolean setupIpLike) %7B%0A        m_setupIpLike = setupIpLike;%0A    %7D%0A
 %7D%0A

Add functionality to this test case to setup the iplike function in the database.