Skip to content

Commit

Permalink
Project test and annotations(documentations).
Browse files Browse the repository at this point in the history
Created more tests that protect all behaviors expected in GitHub
Entities pre-defined by other Groundhog contributor which maybe can be
affected by some code change in basic classes.
Improved Project anotation.
  • Loading branch information
marlonwc3 committed Feb 19, 2014
1 parent 9f40083 commit a2ae7f6
Show file tree
Hide file tree
Showing 4 changed files with 112 additions and 22 deletions.
45 changes: 40 additions & 5 deletions src/java/main/br/ufpe/cin/groundhog/Project.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
* <h1>Project - <i>Represents a software project in Groundhog</i> </h1>
* <p>
* This Class support the base of <i>Groundhog</i> and maybe the most important Class, because like
* we can found at <a href="http://en.wikipedia.org/wiki/GitHub"><i>Wikipedia</i></a> <i>"GitHub is a web-based hosting service for software development projects that use the Git revision control system."</i>.
* A Project object contains all entities that in some way are connected.
* A <i>Groundhog</i> user want to extract metrics from projects hosted on <a href="https://github.com/"><i>Github</i></a>, so this Class can give support to all data that a project can have
* and consequently extract metrics from these.
* </p>
*
* @author
* <ul>
* <li>fjsj</li>
* <li>gustavopinto</li>
* <li>Rodrigo Alves</li>
* </ul>
* @since 0.0.1
*/

@Entity("projects")
public class Project extends GitHubEntity {
@SerializedName("id")
@Indexed(unique=true, dropDups=true)
@Id private int id;

@SerializedName("name")
Expand All @@ -34,7 +49,7 @@ public class Project extends GitHubEntity {
@Reference private List<Issue> issues;
@Reference private List<Milestone> milestones;
@Reference private List<Commit> commits;
@Reference private List<User> contributors;
@Reference private List<Contributor> contributors;

@Reference private User user;
private SCM scm;
Expand Down Expand Up @@ -459,11 +474,11 @@ public void setCommits(List<Commit> commits) {
* Returns the list of contributors of the project as GitHub users
* @return
*/
public List<User> getContributors() {
public List<Contributor> getContributors() {
return this.contributors;
}

public void setContributors(List<User> contributors) {
public void setContributors(List<Contributor> contributors) {
this.contributors = contributors;
}

Expand All @@ -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
*
Expand Down Expand Up @@ -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);
Expand Down
18 changes: 9 additions & 9 deletions src/java/main/br/ufpe/cin/groundhog/Release.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,15 @@
* <p>The attributes are at form bellow:</p>
* <p>Class/type attributeName: What he represent </p>
* <ul>
* <li> String tagName: Tag Name of the Release on GitHub.
* <li> String name: The name of the Release on GitHub.
* <li> 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.
* <li> String body: The Markdown-syntax-based description of the Release.
* <li> String assetsUrl: That present a full project history beyond Git artifacts
* <li> boolean draft: If the Release is a draft (unpublished) or not.
* <li> booelan preRelease: If the Release is or not a full release.
* <li> Date createdAt: When the Release was created.
* <li> Date publishedAt: When the Release was published.
* <li> <b>String</b> tagName: Tag Name of the Release on GitHub.
* <li> <b>String</b> name: The name of the Release on GitHub.
* <li> <b>String</b> 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.
* <li> <b>String</b> body: The Markdown-syntax-based description of the Release.
* <li> <b>String</b> assetsUrl: That present a full project history beyond Git artifacts
* <li> <b>boolean</b> draft: If the Release is a draft (unpublished) or not.
* <li> <b>booelan</b> preRelease: If the Release is or not a full release.
* <li> <b>Date</b> createdAt: When the Release was created.
* <li> <b>Date</b> publishedAt: When the Release was published.
*
* </ul>
* <p> These descriptions can also be seen in the Get methods. </p>
Expand Down
68 changes: 60 additions & 8 deletions src/java/test/br/ufpe/cin/groundhog/EntityTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
}

/**
Expand Down Expand Up @@ -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.
* */
Expand All @@ -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();
}
Expand All @@ -104,5 +107,54 @@ public void testRelease(){
}
}

/**
* <p>Test all basic methods on {@link Project} class.</p>
* */
@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<Commit> commitsTest = new ArrayList<>();
ArrayList<Issue> 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();

}
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,9 @@ public void testGetAllProjectReleases() {
List<Release> releases = searchGitHub.getAllProjectReleases(project);

Assert.assertNotNull(releases);



} catch (Exception e) {
e.printStackTrace();
Assert.fail();
Expand Down

2 comments on commit a2ae7f6

@marlonwc3
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I forgot to specify on commit description:
Changes on ID attribute. ID now it's a "Unique" (see decorator above ID attribute) field on DB and is base for equals method.

Related to #67

@marlonwc3
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Relatedto #20 too

Please sign in to comment.