package org.csstudio.config.ioconfig.model;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;

import java.sql.Date;
import java.util.HashSet;
import java.util.Set;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;

public class FacilityDBOTest {

    @Test
    public void createFacility() throws PersistenceException{
        final FacilityDBO facility = new FacilityDBO();
        facility.setCreatedBy("Creater");
        facility.setCreatedOn(Date.valueOf("2011-11-11"));
        facility.setUpdatedBy("Updater");
        facility.setUpdatedOn(Date.valueOf("2012-12-12"));
        facility.setDescription("description line 1\r\ndescription line 2");
        final DocumentDBO document = new DocumentDBO("subDoc","descDoc","keyDoc");
        final Set<DocumentDBO> docs = new HashSet<DocumentDBO>();
        docs.add(document);
        facility.setDocuments(docs);
        facility.setName("FacNameTest");
        facility.setSortIndexNonHibernate((short)12);
        facility.setVersion(11);

        assertEquals(0,facility.getId());
        assertEquals(null, facility.getParent());
        assertEquals("Creater", facility.getCreatedBy());
        assertEquals(Date.valueOf("2011-11-11"),facility.getCreatedOn());
        assertEquals("Updater", facility.getUpdatedBy());
        assertEquals(Date.valueOf("2012-12-12"), facility.getUpdatedOn());
        assertEquals("description line 1\r\ndescription line 2",facility.getDescription());
        assertEquals(docs,facility.getDocuments());
        assertEquals("FacNameTest",facility.getName());
        assertEquals((short)12, (short) facility.getSortIndex());
        assertEquals(11,facility.getVersion());

        facility.localSave();

        assertTrue(facility.getId()>0);
        assertEquals(null, facility.getParent());
        assertEquals("Creater", facility.getCreatedBy());
        assertEquals(Date.valueOf("2011-11-11"),facility.getCreatedOn());
        assertEquals("Updater", facility.getUpdatedBy());
        assertEquals(Date.valueOf("2012-12-12"), facility.getUpdatedOn());
        assertEquals("description line 1\r\ndescription line 2",facility.getDescription());
        assertEquals(docs,facility.getDocuments());
        assertEquals("FacNameTest",facility.getName());
        assertEquals((short)12, (short) facility.getSortIndex());
        assertEquals(11,facility.getVersion());
    }
    @Before
    public void setUp() throws Exception {
        Repository.injectIRepository(new DummyRepository());
    }
    @After
    public void setDown() {
        Repository.injectIRepository(null);
    }

}

@@ -38,16 +38,50 @@
 model;%0A%0A
+import static org.junit.Assert.*;%0A
 import s
@@ -117,16 +117,16 @@
 Equals;%0A
-
 import s
@@ -413,343 +413,8 @@
 on%7B%0A
-        final FacilityDBO facility = new FacilityDBO();%0A        facility.setCreatedBy(%22Creater%22);%0A        facility.setCreatedOn(Date.valueOf(%222011-11-11%22));%0A        facility.setUpdatedBy(%22Updater%22);%0A        facility.setUpdatedOn(Date.valueOf(%222012-12-12%22));%0A        facility.setDescription(%22description line 1%5Cr%5Cndescription line 2%22);%0A
     
@@ -599,165 +599,73 @@
    f
+inal F
 acility
-.setDocuments(docs);%0A        facility.setName(%22FacNameTest%22);%0A        facility.setSortIndexNonHibernate((short)12);%0A        facility.setVersion(11
+DBO facility = CreateFacility(%22FacNameTest%22, docs
 );%0A
-%0A
     
@@ -1976,32 +1976,32 @@
 etSortIndex());%0A
-
         assertEq
@@ -2034,24 +2034,1713 @@
 n());%0A    %7D%0A
+    %0A    @Test%0A    public void compareFacilitys() throws Exception %7B%0A        final DocumentDBO document = new DocumentDBO(%22subDoc%22,%22descDoc%22,%22keyDoc%22);%0A        final Set%3CDocumentDBO%3E docs = new HashSet%3CDocumentDBO%3E();%0A        docs.add(document);%0A        final FacilityDBO facility1 = CreateFacility(%22FacNameTest1%22, docs);%0A        final FacilityDBO facility2 = CreateFacility(%22FacNameTest2%22, docs);%0A        %0A        facility1.localSave();%0A        facility2.localSave();%0A        %0A        assertTrue(facility1.equals(facility1));%0A        assertTrue(facility2.equals(facility2));%0A        assertFalse(facility1.equals(facility2));%0A        assertFalse(facility2.equals(facility1));%0A        %0A        assertEquals(facility1, facility1);%0A        assertEquals(facility2, facility2);%0A        %0A        assertNotSame(facility1, facility2);%0A        assertNotSame(facility2, facility1);%0A        %0A        assertFalse(0==facility1.compareTo(facility2));%0A        assertFalse(0==facility2.compareTo(facility1));%0A        %0A    %7D%0A    /**%0A     * @param string%0A     * @param docs%0A     * @return%0A     */%0A    private FacilityDBO CreateFacility(String string, Set%3CDocumentDBO%3E docs) %7B%0A        final FacilityDBO facility = new FacilityDBO();%0A        facility.setCreatedBy(%22Creater%22);%0A        facility.setCreatedOn(Date.valueOf(%222011-11-11%22));%0A        facility.setUpdatedBy(%22Updater%22);%0A        facility.setUpdatedOn(Date.valueOf(%222012-12-12%22));%0A        facility.setDescription(%22description line 1%5Cr%5Cndescription line 2%22);%0A        facility.setDocuments(docs);%0A        facility.setName(%22FacNameTest%22);%0A        facility.setSortIndexNonHibernate((short)12);%0A        facility.setVersion(11);%0A        return facility;%0A    %7D%0A
     @Before%0A

Test compare