package edu.northwestern.bioinformatics.studycalendar.database;

import edu.northwestern.bioinformatics.studycalendar.testing.DaoTestCase;
import gov.nih.nci.security.UserProvisioningManager;
import gov.nih.nci.security.SecurityServiceProvider;
import gov.nih.nci.security.dao.GroupSearchCriteria;
import gov.nih.nci.security.dao.SearchCriteria;
import gov.nih.nci.security.authorization.domainobjects.Application;
import gov.nih.nci.security.authorization.domainobjects.Group;


import java.util.Set;
import java.util.List;
import java.io.FileInputStream;

import org.dbunit.dataset.IDataSet;
import org.dbunit.dataset.xml.FlatXmlDataSet;

public class UserProvisioningManagerTest extends DaoTestCase {
    String dataFileName = "uptdata_studycal.xml";
    String path="/Users/johndzak/studycalendar/trunk/test/unit/edu/northwestern/bioinformatics/studycalendar/database/";

    // Can set database and ApplicationSecurityConfig through runtime params too
    // -Dconfig.database=studycalendar_test
    // -Dgov.nih.nci.security.configFile=/Users/johndzak/studycalendar/trunk/build/csm/ApplicationSecurityConfig.xml

    @Override
    protected void setUp() throws Exception {
        super.setUp();    //To change body of overridden methods use File | Settings | File Templates.
        System.setProperty("gov.nih.nci.security.configFile", "/Users/johndzak/studycalendar/trunk/build/csm/ApplicationSecurityConfig.xml");
    }

    protected String getTestDataFileName() {
        return path + dataFileName;
    }


    protected IDataSet getDataSet() throws Exception {
        return new FlatXmlDataSet(new FileInputStream(getTestDataFileName()));
    }

    public void testGetCsmGroups() throws Exception {
        UserProvisioningManager up = (UserProvisioningManager) getApplicationContext().getBean("userProvisioningManager");
        assertNotNull("User Provisioning Manager Null", up);

        Application ap = up.getApplicationById("2");
        assertNotNull("Appliction is null", ap );

        Set groups = ap.getGroups();
        assertNull("Groups are null" , groups);  // Assert Csm is broken
    }

    public void testGetCsmGroups_2() throws Exception {
        UserProvisioningManager up = (UserProvisioningManager) getApplicationContext().getBean("userProvisioningManager");
        Group group = new Group();

        SearchCriteria searchCriteria = new GroupSearchCriteria(group);
        List<Group> groups = up.getObjects(searchCriteria);

        assertNotNull("Groups are null" , groups);
        assertTrue(groups.size() > 0);
    }
}

@@ -747,24 +747,26 @@
 l.xml%22;%0A    
+//
 String path=
@@ -1284,16 +1284,18 @@
 %0A       
+//
  System.
@@ -1491,15 +1491,8 @@
 turn
- path +
  dat
@@ -1509,24 +1509,26 @@
 %0A    %7D%0A%0A%0A   
+/*
  protected I
@@ -1647,24 +1647,26 @@
 e()));%0A    %7D
+*/
 %0A%0A    public
@@ -1705,32 +1705,34 @@
 Exception %7B%0A    
+/*
     UserProvisio
@@ -2110,16 +2110,24 @@
  broken%0A
+     */%0A
     %7D%0A%0A 
@@ -2181,24 +2181,26 @@
 ption %7B%0A    
+/*
     UserProv
@@ -2565,16 +2565,24 @@
 ) %3E 0);%0A
+     */%0A
     %7D%0A%7D%0A

Update test