|
@@ -0,0 +1,169 @@
|
|
|
+package com.mooctest.crowd.domain.domainobject;
|
|
|
+
|
|
|
+import com.mooctest.crowd.domain.command.TestProjectCommand;
|
|
|
+import com.mooctest.crowd.domain.exception.TestProjectNotExistException;
|
|
|
+import com.mooctest.crowd.domain.repository.TestProjectRepo;
|
|
|
+import org.junit.Test;
|
|
|
+
|
|
|
+import java.io.File;
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.Date;
|
|
|
+import java.util.List;
|
|
|
+
|
|
|
+import static org.junit.Assert.*;
|
|
|
+
|
|
|
+/**
|
|
|
+ * @author guochao
|
|
|
+ * @date 2019/7/6 18:17
|
|
|
+ */
|
|
|
+public class GeneralUserTest {
|
|
|
+
|
|
|
+ @Test
|
|
|
+ public void should_return_success_when_create_test_project_success(){
|
|
|
+ // arrange
|
|
|
+ TestProjectCommand testProjectCommand = new TestProjectCommand();
|
|
|
+ testProjectCommand.setName("PROJECT_ONE");
|
|
|
+ testProjectCommand.setDescription("DESCRIPTION");
|
|
|
+ testProjectCommand.setProjectFile(new File("PROJECTFILE.TXT"));
|
|
|
+ testProjectCommand.setRequirement(new File("REQUIREMENT.TXT"));
|
|
|
+ testProjectCommand.setQuotedPrice(200.00);
|
|
|
+ testProjectCommand.setCreatTime(new Date());
|
|
|
+ TestProjectRepo testProjectRepo = new TestProjectRepo();
|
|
|
+
|
|
|
+ // action
|
|
|
+ TestProject testProject = testProjectRepo.addTestProject(testProjectCommand);
|
|
|
+
|
|
|
+ // assert
|
|
|
+ assertNotNull(testProject);
|
|
|
+ assertEquals(testProject.getName(),testProjectCommand.getName());
|
|
|
+ }
|
|
|
+
|
|
|
+ @Test
|
|
|
+ public void should_return_test_project_when_test_project_exist() throws TestProjectNotExistException {
|
|
|
+ // arrange
|
|
|
+ TestProjectCommand testProjectCommand = new TestProjectCommand();
|
|
|
+ testProjectCommand.setId(new Long(10001));
|
|
|
+ TestProjectRepo testProjectRepo = new TestProjectRepo();
|
|
|
+ // action
|
|
|
+ TestProject testProject = testProjectRepo.getByID(testProjectCommand.getId());
|
|
|
+
|
|
|
+ // assert
|
|
|
+ assertNotNull(testProject);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Test(expected = TestProjectNotExistException.class)
|
|
|
+ public void should_throw_when_test_project_not_exist() throws TestProjectNotExistException {
|
|
|
+ // arrange
|
|
|
+ TestProjectCommand testProjectCommand = new TestProjectCommand();
|
|
|
+ testProjectCommand.setId(new Long(10002));
|
|
|
+ TestProjectRepo testProjectRepo = new TestProjectRepo();
|
|
|
+ // action
|
|
|
+ TestProject testProject = testProjectRepo.getByID(testProjectCommand.getId());
|
|
|
+ }
|
|
|
+
|
|
|
+ @Test
|
|
|
+ public void should_return_true_when_remove_test_project_success() throws TestProjectNotExistException {
|
|
|
+ // arrange
|
|
|
+ TestProject testProject = createTestProject();
|
|
|
+ TestProjectRepo testProjectRepo = new TestProjectRepo();
|
|
|
+
|
|
|
+ // action
|
|
|
+ boolean result = testProjectRepo.removeTestProject(testProject);
|
|
|
+
|
|
|
+ // assert
|
|
|
+ assertTrue(result);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Test(expected = TestProjectNotExistException.class)
|
|
|
+ public void should_throw_when_remove_not_exist_test_project() throws TestProjectNotExistException {
|
|
|
+ // arrange
|
|
|
+ TestProject testProject = new TestProject();
|
|
|
+ testProject.setId(new Long(10002));
|
|
|
+ TestProjectRepo testProjectRepo = new TestProjectRepo();
|
|
|
+
|
|
|
+ // action
|
|
|
+ boolean result = testProjectRepo.removeTestProject(testProject);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Test
|
|
|
+ public void should_return_true_when_update_test_project_success() throws TestProjectNotExistException {
|
|
|
+ // arrange
|
|
|
+ TestProject testProject = createTestProject();
|
|
|
+ TestProjectRepo testProjectRepo = new TestProjectRepo();
|
|
|
+
|
|
|
+ // action
|
|
|
+ boolean result = testProjectRepo.updateTestProject(testProject);
|
|
|
+
|
|
|
+ // assert
|
|
|
+ assertTrue(result);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Test(expected = TestProjectNotExistException.class)
|
|
|
+ public void should_throw_when_update_test_project_not_exist() throws TestProjectNotExistException {
|
|
|
+ // arrange
|
|
|
+ TestProject testProject = new TestProject();
|
|
|
+ testProject.setId(new Long(10002));
|
|
|
+ TestProjectRepo testProjectRepo = new TestProjectRepo();
|
|
|
+
|
|
|
+ // action
|
|
|
+ testProjectRepo.updateTestProject(testProject);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Test
|
|
|
+ public void should_return_ture_when_update_test_project_list_success() throws TestProjectNotExistException {
|
|
|
+ // arrange
|
|
|
+ List<TestProject> testProjects = new ArrayList<TestProject>();
|
|
|
+ TestProject testProject1 = createTestProject();
|
|
|
+ testProjects.add(testProject1);
|
|
|
+ TestProject testProject = new TestProject();
|
|
|
+ testProject.setId(new Long(10002));
|
|
|
+ testProject.setName("PROJECT_TWO");
|
|
|
+ testProject.setDescription("DESCRIPTION");
|
|
|
+ testProject.setProjectFile(new File("PROJECTFILE.TXT"));
|
|
|
+ testProject.setRequirement(new File("REQUIREMENT.TXT"));
|
|
|
+ testProject.setQuotedPrice(200.00);
|
|
|
+ testProject.setCreatTime(new Date());
|
|
|
+ testProjects.add(testProject);
|
|
|
+ TestProjectRepo testProjectRepo = new TestProjectRepo();
|
|
|
+
|
|
|
+ // action
|
|
|
+ boolean result = testProjectRepo.updateTestProjectList(testProjects);
|
|
|
+
|
|
|
+ // assert
|
|
|
+ assertTrue(result);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Test(expected = TestProjectNotExistException.class)
|
|
|
+ public void should_throw_when_update_test_project_list_not_exist() throws TestProjectNotExistException {
|
|
|
+ // arrange
|
|
|
+ List<TestProject> testProjects = new ArrayList<TestProject>();
|
|
|
+ TestProject testProject1 = createTestProject();
|
|
|
+ testProjects.add(testProject1);
|
|
|
+ TestProject testProject = new TestProject();
|
|
|
+ testProject.setId(new Long(10003));
|
|
|
+ testProject.setName("PROJECT_TWO");
|
|
|
+ testProject.setDescription("DESCRIPTION");
|
|
|
+ testProject.setProjectFile(new File("PROJECTFILE.TXT"));
|
|
|
+ testProject.setRequirement(new File("REQUIREMENT.TXT"));
|
|
|
+ testProject.setQuotedPrice(200.00);
|
|
|
+ testProject.setCreatTime(new Date());
|
|
|
+ testProjects.add(testProject);
|
|
|
+ TestProjectRepo testProjectRepo = new TestProjectRepo();
|
|
|
+
|
|
|
+ // action
|
|
|
+ boolean result = testProjectRepo.updateTestProjectList(testProjects);
|
|
|
+ }
|
|
|
+
|
|
|
+ private TestProject createTestProject(){
|
|
|
+ TestProject testProject = new TestProject();
|
|
|
+ testProject.setId(new Long(10001));
|
|
|
+ testProject.setName("PROJECT_ONE");
|
|
|
+ testProject.setDescription("DESCRIPTION");
|
|
|
+ testProject.setProjectFile(new File("PROJECTFILE.TXT"));
|
|
|
+ testProject.setRequirement(new File("REQUIREMENT.TXT"));
|
|
|
+ testProject.setQuotedPrice(200.00);
|
|
|
+ testProject.setCreatTime(new Date());
|
|
|
+ return testProject;
|
|
|
+ }
|
|
|
+
|
|
|
+}
|