package com.validation.manager.core.db;

import com.validation.manager.core.DataBaseManager;
import com.validation.manager.core.db.controller.ProjectJpaController;
import com.validation.manager.core.server.core.ProjectServer;
import com.validation.manager.core.server.core.StepServer;
import com.validation.manager.core.server.core.TestCaseServer;
import com.validation.manager.test.AbstractVMTestCase;
import com.validation.manager.test.TestHelper;
import java.util.logging.Level;
import java.util.logging.Logger;
import static junit.framework.TestCase.assertEquals;
import org.junit.After;
import org.junit.Test;

/**
 *
 * @author Javier A. Ortiz Bultron <javier.ortiz.78@gmail.com>
 */
public class ProjectTest extends AbstractVMTestCase {

    Project p;
    private static final Logger LOG
            = Logger.getLogger(ProjectTest.class.getName());

    @After
    public void clear() {
        if (p != null) {
            ProjectServer.deleteProject(p);
        }
    }

    /**
     * Test of toString method, of class Project.
     */
    @Test
    public void testCreateAndDestroy() {
        try {
            VmUser user = TestHelper.createUser("test1",
                    "password", "first", "test@test.com", "last");
            p = TestHelper.createProject("New Project", "Notes");
            ProjectServer project = new ProjectServer(p);
            project.setNotes("Notes 2");
            project.write2DB();
            assertTrue(new ProjectJpaController(
                    DataBaseManager.getEntityManagerFactory())
                    .findProject(project.getId()).getNotes().equals(project.getNotes()));
            //Create requirements
            System.out.println("Create Requirement Spec");
            RequirementSpec rss = null;
            try {
                rss = TestHelper.createRequirementSpec("Test", "Test",
                        project, 1);
            } catch (Exception ex) {
                LOG.log(Level.SEVERE, null, ex);
                fail();
            }
            System.out.println("Create Requirement Spec Node");
            RequirementSpecNode rsns = null;
            try {
                rsns = TestHelper.createRequirementSpecNode(
                        rss, "Test", "Test", "Test");
            } catch (Exception ex) {
                LOG.log(Level.SEVERE, null, ex);
                fail();
            }
            Requirement r = TestHelper.createRequirement("SRS-SW-0001",
                    "Sample requirement", rsns.getRequirementSpecNodePK(), "Notes", 1, 1);
            //Create Test
            com.validation.manager.core.db.Test test
                    = TestHelper.createTest("Test #1", "Testing",
                    "Test #1 scope");
            //Create Test Case
            TestCase tc = TestHelper.createTestCase("Dummy", new Short("1"),
                    "Expected Results", test, /*user,*/ "Summary");
            //Add steps
            for (int i = 1; i < 6; i++) {
                System.out.println("Adding step: " + i);
                tc = TestHelper.addStep(tc, i, "Step " + i, "Note " + i);
                Step step = tc.getStepList().get(i - 1);
                TestHelper.addRequirementToStep(step, r);
                new TestCaseServer(tc).write2DB();
                assertEquals(1, new StepServer(step).getRequirementList().size());
            }
            //Create test Project
            TestProject tp = TestHelper.createTestProject("Test Project");
            //Create test plan
            TestPlan plan = TestHelper.createTestPlan(tp, "Notes", true, true);
            //Add test case to test
            TestHelper.addTestCaseToTest(test, tc);
            //Add test to plan
            TestHelper.addTestToPlan(plan, test);
        } catch (Exception ex) {
            LOG.log(Level.SEVERE, null, ex);
            fail();
        }
    }
}

@@ -439,24 +439,56 @@
 TestHelper;%0A
+import java.text.MessageFormat;%0A
 import java.
@@ -1153,19 +1153,9 @@
     
-VmUser user
+p
  = T
@@ -1174,152 +1174,108 @@
 eate
-User(%22test1%22,%0A                    %22password%22, %22first%22, %22test@test.com%22, %22last%22);%0A            p = TestHelper.createProject(%22New Project%22, %22Notes%22
+Project(%22New Project%22, %22Notes%22);%0A            assertEquals(0, ProjectServer.getRequirements(p).size()
 );%0A 
@@ -1652,34 +1652,24 @@
         
-System.out.println
+LOG.info
 (%22Create
@@ -1991,34 +1991,24 @@
         
-System.out.println
+LOG.info
 (%22Create
@@ -2663,16 +2663,24 @@
         
+        
 %22Test #1
@@ -2951,26 +2951,37 @@
     
-System.out.println
+LOG.info(MessageFormat.format
 (%22Ad
@@ -2991,22 +2991,25 @@
 g step: 
-%22 +
+%7B0%7D%22,
  i)
+)
 ;%0A      
@@ -3728,16 +3728,86 @@
  test);%0A
+            assertEquals(1, ProjectServer.getRequirements(p).size());%0A
         

Add test for the getRequirements method.