This repository has been archived by the owner on Nov 9, 2017. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'integration/master' into update-stats
- Loading branch information
Showing
6 changed files
with
282 additions
and
13 deletions.
There are no files selected for viewing
82 changes: 82 additions & 0 deletions
82
zanata-common-api/src/main/java/org/zanata/rest/dto/TransUnitStatus.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
package org.zanata.rest.dto; | ||
|
||
import java.io.Serializable; | ||
|
||
import javax.validation.constraints.NotNull; | ||
|
||
import org.codehaus.jackson.annotate.JsonIgnoreProperties; | ||
import org.codehaus.jackson.annotate.JsonPropertyOrder; | ||
import org.codehaus.jackson.map.annotate.JsonSerialize; | ||
import org.zanata.common.ContentState; | ||
|
||
@JsonIgnoreProperties(ignoreUnknown = true) | ||
@JsonPropertyOrder({ "id", "resId", "status"}) | ||
@JsonSerialize(include = JsonSerialize.Inclusion.NON_NULL) | ||
public class TransUnitStatus implements Serializable { | ||
|
||
private Long id; | ||
private String resId; | ||
private ContentState status; | ||
|
||
public TransUnitStatus() { | ||
this(null, null, null); | ||
} | ||
|
||
public TransUnitStatus(Long id, String resId, ContentState status) { | ||
this.id = id; | ||
this.resId = resId; | ||
this.status = status; | ||
} | ||
|
||
@NotNull | ||
public Long getId() { | ||
return id; | ||
} | ||
|
||
public void setId(Long id) { | ||
this.id = id; | ||
} | ||
|
||
@NotNull | ||
public String getResId() { | ||
return resId; | ||
} | ||
|
||
public void setResId(String resId) { | ||
this.resId = resId; | ||
} | ||
|
||
@NotNull | ||
public ContentState getStatus() { | ||
return status; | ||
} | ||
|
||
public void setStatus(ContentState status) { | ||
this.status = status; | ||
} | ||
|
||
@Override | ||
public boolean equals(Object o) { | ||
if (this == o) return true; | ||
if (!(o instanceof TransUnitStatus)) return false; | ||
|
||
TransUnitStatus status1 = (TransUnitStatus) o; | ||
|
||
if (id != null ? !id.equals(status1.id) : status1.id != null) | ||
return false; | ||
if (resId != null ? !resId.equals(status1.resId) : | ||
status1.resId != null) | ||
return false; | ||
if (status != status1.status) return false; | ||
|
||
return true; | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
int result = id != null ? id.hashCode() : 0; | ||
result = 31 * result + (resId != null ? resId.hashCode() : 0); | ||
result = 31 * result + (status != null ? status.hashCode() : 0); | ||
return result; | ||
} | ||
} |
120 changes: 120 additions & 0 deletions
120
zanata-common-api/src/main/java/org/zanata/rest/dto/User.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,120 @@ | ||
package org.zanata.rest.dto; | ||
|
||
import java.io.Serializable; | ||
import java.util.List; | ||
|
||
import javax.validation.constraints.NotNull; | ||
|
||
import org.codehaus.jackson.annotate.JsonIgnoreProperties; | ||
import org.codehaus.jackson.annotate.JsonProperty; | ||
import org.codehaus.jackson.annotate.JsonPropertyOrder; | ||
import org.codehaus.jackson.map.annotate.JsonSerialize; | ||
import org.hibernate.validator.constraints.Email; | ||
import org.hibernate.validator.constraints.NotEmpty; | ||
|
||
@JsonIgnoreProperties(ignoreUnknown = true) | ||
@JsonPropertyOrder({ "username", "email", "name", "imageUrl", "languageTeams"}) | ||
@JsonSerialize(include = JsonSerialize.Inclusion.NON_NULL) | ||
public class User implements Serializable { | ||
|
||
private String username; | ||
private String email; | ||
private String name; | ||
private String imageUrl; | ||
private List<String> languageTeams; | ||
|
||
public User() { | ||
this(null, null, null, null, null); | ||
} | ||
|
||
public User(String username, String email, String name, | ||
String imageUrl, List<String> languageTeams) { | ||
this.username = username; | ||
this.email = email; | ||
this.name = name; | ||
this.imageUrl = imageUrl; | ||
this.languageTeams = languageTeams; | ||
} | ||
|
||
@NotEmpty | ||
@JsonProperty("username") | ||
public String getUsername() { | ||
return username; | ||
} | ||
|
||
public void setUsername(String username) { | ||
this.username = username; | ||
} | ||
|
||
@NotNull | ||
@JsonProperty("email") | ||
public String getEmail() { | ||
return email; | ||
} | ||
|
||
public void setEmail(String email) { | ||
this.email = email; | ||
} | ||
|
||
@NotEmpty | ||
@JsonProperty("name") | ||
public String getName() { | ||
return name; | ||
} | ||
|
||
public void setName(String name) { | ||
this.name = name; | ||
} | ||
|
||
@NotEmpty | ||
@JsonProperty("imageUrl") | ||
public String getImageUrl() { | ||
return imageUrl; | ||
} | ||
|
||
public void setImageUrl(String imageUrl) { | ||
this.imageUrl = imageUrl; | ||
} | ||
|
||
public List<String> getLanguageTeams() { | ||
return languageTeams; | ||
} | ||
|
||
public void setLanguageTeams(List<String> languageTeams) { | ||
this.languageTeams = languageTeams; | ||
} | ||
|
||
@Override | ||
public boolean equals(Object o) { | ||
if (this == o) return true; | ||
if (!(o instanceof User)) return false; | ||
|
||
User user = (User) o; | ||
|
||
if (username != null ? !username.equals(user.username) : | ||
user.username != null) return false; | ||
if (email != null ? !email.equals(user.email) : user.email != null) | ||
return false; | ||
if (name != null ? !name.equals(user.name) : user.name != null) | ||
return false; | ||
if (imageUrl != null ? !imageUrl.equals(user.imageUrl) : | ||
user.imageUrl != null) return false; | ||
return !(languageTeams != null ? | ||
!languageTeams.equals(user.languageTeams) : | ||
user.languageTeams != null); | ||
|
||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
int result = username != null ? username.hashCode() : 0; | ||
result = 31 * result + (email != null ? email.hashCode() : 0); | ||
result = 31 * result + (name != null ? name.hashCode() : 0); | ||
result = 31 * result + (imageUrl != null ? imageUrl.hashCode() : 0); | ||
result = | ||
31 * result + | ||
(languageTeams != null ? languageTeams.hashCode() : 0); | ||
return result; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
zanata-common-api/src/test/java/org/zanata/rest/dto/TransUnitStatusTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package org.zanata.rest.dto; | ||
|
||
import java.io.IOException; | ||
|
||
import org.codehaus.jackson.map.ObjectMapper; | ||
import org.junit.Test; | ||
import org.zanata.common.ContentState; | ||
|
||
import static org.hamcrest.MatcherAssert.assertThat; | ||
import static org.hamcrest.Matchers.equalTo; | ||
|
||
/** | ||
* @author Alex Eng <a href="mailto:aeng@redhat.com">aeng@redhat.com</a> | ||
*/ | ||
public class TransUnitStatusTest { | ||
|
||
ObjectMapper om = new ObjectMapper(); | ||
|
||
@Test | ||
public void testJsonOutput() throws IOException { | ||
String json = | ||
"{\n" + " \"id\" : \"100\",\n" + " \"resId\" : \"rest id\",\n " | ||
+ "\"status\" : \"NeedReview\"" + | ||
"\n}"; | ||
|
||
TransUnitStatus status = om.readValue(json, TransUnitStatus.class); | ||
|
||
TransUnitStatus expected = new TransUnitStatus(100L, "rest id", | ||
ContentState.NeedReview); | ||
|
||
assertThat(status, equalTo(expected)); | ||
} | ||
} |
33 changes: 33 additions & 0 deletions
33
zanata-common-api/src/test/java/org/zanata/rest/dto/UserTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package org.zanata.rest.dto; | ||
|
||
import java.io.IOException; | ||
import java.util.ArrayList; | ||
|
||
import org.codehaus.jackson.map.ObjectMapper; | ||
import org.junit.Test; | ||
|
||
import static org.hamcrest.MatcherAssert.assertThat; | ||
import static org.hamcrest.Matchers.equalTo; | ||
|
||
/** | ||
* @author Alex Eng <a href="mailto:aeng@redhat.com">aeng@redhat.com</a> | ||
*/ | ||
public class UserTest { | ||
|
||
ObjectMapper om = new ObjectMapper(); | ||
|
||
@Test | ||
public void testJsonOutput() throws IOException { | ||
String json = | ||
"{\"username\":\"_username\",\"email\":\"test@example.com\",\"name\":\"testUser\",\"imageUrl\":\"url\",\"languageTeams\":[\"English\"],\"loggedIn\":true}"; | ||
User user = om.readValue(json, User.class); | ||
|
||
ArrayList<String> list = new ArrayList<String>(); | ||
list.add("English"); | ||
|
||
User expected = new User("_username", "test@example.com", "testUser", | ||
"url", list); | ||
|
||
assertThat(user, equalTo(expected)); | ||
} | ||
} |