package com.taskadapter.redmineapi;

import junit.framework.Assert;

import org.junit.BeforeClass;
import org.junit.Test;

import com.taskadapter.redmineapi.RedmineException;
import com.taskadapter.redmineapi.RedmineManager;
import com.taskadapter.redmineapi.bean.Project;

public class ParentProjectTest {

    private static RedmineManager mgr;

  @BeforeClass
    public static void oneTimeSetUp() {
    TestConfig testConfig = new TestConfig();
        mgr = new RedmineManager(testConfig.getURI());
        mgr.setLogin(testConfig.getLogin());
        mgr.setPassword(testConfig.getPassword());
    }

    @Test
    public void testProjectParentId() throws RedmineException {
        String parentKey = "parent";
        String childKey = "child";

        Project parentProject = createProject(parentKey, "Parent Project", null);
        Project childProject = 
                createProject(childKey, "Child Project", parentProject.getId());

        try {
            Assert.assertEquals(childProject.getParentId(), parentProject.getId());
        } finally {
            mgr.deleteProject(childKey);
            mgr.deleteProject(parentKey);
        }
    }

    /**
     * @param parentId id of the parent project or null
     */
    private Project createProject(String key, String name, Integer parentId) throws RedmineException {
        Project newProject = new Project();
        newProject.setIdentifier(key);
        newProject.setName(name);
        if (parentId != null)
            newProject.setParentId(parentId);
        mgr.createProject(newProject);
        return mgr.getProjectByKey(key);
    }

}
@@ -41,33 +41,49 @@
 ort 
-junit.framework.Asser
+com.taskadapter.redmineapi.bean.Projec
 t;%0A
-%0A
 impo
@@ -143,149 +143,44 @@
 ort 
-com.taskadapter.redmineapi.RedmineException;%0Aimport com.taskadapter.redmineapi.RedmineManager;%0Aimport com.taskadapter.redmineapi.bean.Project
+static org.junit.Assert.assertEquals
 ;%0A%0Ap
@@ -252,16 +252,18 @@
 r mgr;%0A%0A
+  
   @Befor
@@ -269,16 +269,16 @@
 reClass%0A
-
     publ
@@ -309,16 +309,20 @@
 tUp() %7B%0A
+    
     Test
@@ -355,24 +355,24 @@
 stConfig();%0A
-
         mgr 
@@ -547,16 +547,28 @@
 oid 
-testProj
+childProjectGetsCorr
 ectP
@@ -638,16 +638,45 @@
 %22parent%22
+ + System.currentTimeMillis()
 ;%0A      
@@ -702,16 +702,45 @@
  %22child%22
+ + System.currentTimeMillis()
 ;%0A%0A     
@@ -846,17 +846,16 @@
 roject =
- 
 %0A       
@@ -939,24 +939,24 @@
       try %7B%0A
+
             
@@ -955,23 +955,16 @@
         
-Assert.
 assertEq

use unique IDs in ParentProjectTest so that it does not fail - otherwise it can fail when the previous test did not delete the temporary project