diff --git a/src/java/main/br/ufpe/cin/groundhog/Project.java b/src/java/main/br/ufpe/cin/groundhog/Project.java
index 434277b..808d9a8 100644
--- a/src/java/main/br/ufpe/cin/groundhog/Project.java
+++ b/src/java/main/br/ufpe/cin/groundhog/Project.java
@@ -7,18 +7,33 @@
import org.mongodb.morphia.annotations.Entity;
import org.mongodb.morphia.annotations.Id;
+import org.mongodb.morphia.annotations.Indexed;
import org.mongodb.morphia.annotations.Reference;
import com.google.gson.annotations.SerializedName;
/**
- * Represents a software project in Groundhog
- * @author fjsj, gustavopinto, Rodrigo Alves
+ *
Project - Represents a software project in Groundhog
+ *
+ * This Class support the base of Groundhog and maybe the most important Class, because like
+ * we can found at Wikipedia "GitHub is a web-based hosting service for software development projects that use the Git revision control system.".
+ * A Project object contains all entities that in some way are connected.
+ * A Groundhog user want to extract metrics from projects hosted on Github, so this Class can give support to all data that a project can have
+ * and consequently extract metrics from these.
+ *
+ *
+ * @author
+ *
+ * - fjsj
+ * - gustavopinto
+ * - Rodrigo Alves
+ *
* @since 0.0.1
*/
@Entity("projects")
public class Project extends GitHubEntity {
@SerializedName("id")
+ @Indexed(unique=true, dropDups=true)
@Id private int id;
@SerializedName("name")
@@ -34,7 +49,7 @@ public class Project extends GitHubEntity {
@Reference private List issues;
@Reference private List milestones;
@Reference private List commits;
- @Reference private List contributors;
+ @Reference private List contributors;
@Reference private User user;
private SCM scm;
@@ -459,11 +474,11 @@ public void setCommits(List commits) {
* Returns the list of contributors of the project as GitHub users
* @return
*/
- public List getContributors() {
+ public List getContributors() {
return this.contributors;
}
- public void setContributors(List contributors) {
+ public void setContributors(List contributors) {
this.contributors = contributors;
}
@@ -483,6 +498,14 @@ public void setUser(User user) {
this.user = user;
}
+ public int getId() {
+ return id;
+ }
+
+ public void setId(int id) {
+ this.id = id;
+ }
+
/**
* Return true if the project is considered mature
*
@@ -520,6 +543,18 @@ public String getURL() {
return String.format("https://api.github.com/repos/%s/%s", this.getUser().getLogin(), this.getName());
}
+ /**
+ * If two projects have the same ID, then they are equals.
+ * */
+ public boolean equals(Project project){
+ if(this.id == project.getId()){
+ return true;
+ }
+ else{
+ return false;
+ }
+ }
+
@Override
public String toString() {
return String.format("Project(%s, %s)", this.name, this.sourceCodeURL);
diff --git a/src/java/main/br/ufpe/cin/groundhog/Release.java b/src/java/main/br/ufpe/cin/groundhog/Release.java
index 9f3229b..375dde7 100644
--- a/src/java/main/br/ufpe/cin/groundhog/Release.java
+++ b/src/java/main/br/ufpe/cin/groundhog/Release.java
@@ -21,15 +21,15 @@
* The attributes are at form bellow:
* Class/type attributeName: What he represent
*
- * - String tagName: Tag Name of the Release on GitHub.
- *
- String name: The name of the Release on GitHub.
- *
- String targetCommitish: The Commitish value that determines where the Git tag is created from. Can be any branch or commit SHA. Defaults to the repository’s default branch (usually “master”). Unused if the Git tag already exists.
- *
- String body: The Markdown-syntax-based description of the Release.
- *
- String assetsUrl: That present a full project history beyond Git artifacts
- *
- boolean draft: If the Release is a draft (unpublished) or not.
- *
- booelan preRelease: If the Release is or not a full release.
- *
- Date createdAt: When the Release was created.
- *
- Date publishedAt: When the Release was published.
+ *
- String tagName: Tag Name of the Release on GitHub.
+ *
- String name: The name of the Release on GitHub.
+ *
- String targetCommitish: The Commitish value that determines where the Git tag is created from. Can be any branch or commit SHA. Defaults to the repository’s default branch (usually “master”). Unused if the Git tag already exists.
+ *
- String body: The Markdown-syntax-based description of the Release.
+ *
- String assetsUrl: That present a full project history beyond Git artifacts
+ *
- boolean draft: If the Release is a draft (unpublished) or not.
+ *
- booelan preRelease: If the Release is or not a full release.
+ *
- Date createdAt: When the Release was created.
+ *
- Date publishedAt: When the Release was published.
*
*
* These descriptions can also be seen in the Get methods.
diff --git a/src/java/test/br/ufpe/cin/groundhog/EntityTest.java b/src/java/test/br/ufpe/cin/groundhog/EntityTest.java
index f6aee8d..21aa853 100644
--- a/src/java/test/br/ufpe/cin/groundhog/EntityTest.java
+++ b/src/java/test/br/ufpe/cin/groundhog/EntityTest.java
@@ -2,6 +2,10 @@
import static org.junit.Assert.*;
+import java.util.ArrayList;
+import java.util.List;
+
+
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
@@ -19,14 +23,14 @@ public class EntityTest {
private User userTest;
private Contributor contributorTest;
private Release releaseTest;
- private Project fakeProject;
+ private Project projectTest;
@Before
public void setup() {
- fakeProject = new Project("fakeUserLogin", "Fake Project");
- userTest = new User("tls");
- contributorTest = new Contributor("tls");
- releaseTest = new Release(fakeProject, 1);
+ projectTest = new Project("projectUserLogin", "Test Project");
+ userTest = new User("testUserLogin");
+ contributorTest = new Contributor("testUserLogin");
+ releaseTest = new Release(projectTest, 1);
}
/**
@@ -65,8 +69,7 @@ public void testContributor(){
if(!contributorTest.equals(secondContributor)){
Assert.fail();
}
-
-
+
/*
* The Contributor URL must be equals to the URL from a User object that contains the same login.
* */
@@ -92,7 +95,7 @@ public void testRelease(){
* If two Releases have the same ID, then they are equals.
**/
int releaseTestId = releaseTest.getId();
- Release secondRelease = new Release(fakeProject, releaseTestId);
+ Release secondRelease = new Release(projectTest, releaseTestId);
if(!releaseTest.equals(secondRelease)){
Assert.fail();
}
@@ -104,5 +107,54 @@ public void testRelease(){
}
}
+ /**
+ * Test all basic methods on {@link Project} class.
+ * */
+ @Test
+ public void testProject(){
+ try {
+ String loginProjectTest = projectTest.getUser().getLogin();
+ String nameProjectTest = projectTest.getName();
+ Project secondProject = new Project(loginProjectTest, nameProjectTest);
+
+ /*
+ * If two projects have the same ID, then they are equals.
+ * */
+ if(!projectTest.equals(secondProject)){
+ Assert.fail();
+ }
+
+ /*((watchersCount > 3) && (forks_count > 1) && (commits.size() > 100) && (issues.size() > 5));
+ *
+ * If we have Project P that:
+ * P.wachtersCount > 4
+ * P.forks_count > 1
+ * P.commits.size() > 100
+ * P.issues.size() > 5
+ * Then, P.isMature == true
+ * */
+ ArrayList commitsTest = new ArrayList<>();
+ ArrayList issuesTest = new ArrayList<>();
+ for(int i = 0; i < 105; i++){ // add a Commit List that size is bigger than 100.
+ commitsTest.add(new Commit("commitTest", projectTest));
+ }
+ for(int i = 0; i < 8; i++){ // add a Issue List that size is bigger than 8.
+ issuesTest.add(new Issue(projectTest, i, "Open"));
+ }
+ secondProject.setWatchersCount(4);
+ secondProject.setForksCount(2);
+ secondProject.setCommits(commitsTest);
+ secondProject.setIssues(issuesTest);
+
+ /*If all above conditions are met, then secondProject.isMature must be true*/
+ Assert.assertEquals(true, secondProject.isMature());
+
+ } catch (Exception e) {
+ e.printStackTrace();
+ Assert.fail();
+
+ }
+ }
+
}
diff --git a/src/java/test/br/ufpe/cin/groundhog/search/SearchGitHubTest.java b/src/java/test/br/ufpe/cin/groundhog/search/SearchGitHubTest.java
index 43bd5f8..0104c3f 100644
--- a/src/java/test/br/ufpe/cin/groundhog/search/SearchGitHubTest.java
+++ b/src/java/test/br/ufpe/cin/groundhog/search/SearchGitHubTest.java
@@ -119,6 +119,9 @@ public void testGetAllProjectReleases() {
List releases = searchGitHub.getAllProjectReleases(project);
Assert.assertNotNull(releases);
+
+
+
} catch (Exception e) {
e.printStackTrace();
Assert.fail();