Skip to content

Commit

Permalink
add unit test for dto and service
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex Eng committed Feb 6, 2018
1 parent 951b72f commit 0806dcd
Show file tree
Hide file tree
Showing 5 changed files with 365 additions and 13 deletions.
Expand Up @@ -73,4 +73,34 @@ public void setStatus(ContentState status) {
this.status = status;
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;

ReviewData that = (ReviewData) o;

if (transUnitId != null ? !transUnitId.equals(that.transUnitId) :
that.transUnitId != null) return false;
if (revision != null ? !revision.equals(that.revision) :
that.revision != null) return false;
if (comment != null ? !comment.equals(that.comment) :
that.comment != null)
return false;
if (reviewCriteriaId != null ?
!reviewCriteriaId.equals(that.reviewCriteriaId) :
that.reviewCriteriaId != null) return false;
return status == that.status;
}

@Override
public int hashCode() {
int result = transUnitId != null ? transUnitId.hashCode() : 0;
result = 31 * result + (revision != null ? revision.hashCode() : 0);
result = 31 * result + (comment != null ? comment.hashCode() : 0);
result = 31 * result +
(reviewCriteriaId != null ? reviewCriteriaId.hashCode() : 0);
result = 31 * result + (status != null ? status.hashCode() : 0);
return result;
}
}
@@ -1,8 +1,6 @@
package org.zanata.rest.editor.service;

import com.google.common.collect.Lists;
import net.customware.gwt.dispatch.shared.ActionException;
import org.omg.PortableInterceptor.ACTIVE;
import org.zanata.common.EntityStatus;
import org.zanata.common.LocaleId;
import org.zanata.dao.ReviewCriteriaDAO;
Expand All @@ -24,33 +22,48 @@

import javax.enterprise.context.RequestScoped;
import javax.inject.Inject;
import javax.validation.constraints.NotNull;
import javax.ws.rs.Path;
import javax.ws.rs.core.Response;
import java.util.List;


@Path(TranslationReviewResource.SERVICE_PATH)
@RequestScoped
public class TranslationReviewService implements TranslationReviewResource {
private static final org.slf4j.Logger log =
org.slf4j.LoggerFactory.getLogger(TranslationReviewService.class);

@Inject
private TextFlowTargetDAO textFlowTargetDAO;
@Inject
private LocaleService localeServiceImpl;
@Inject
private ZanataIdentity identity;
@Inject
private ReviewCriteriaDAO reviewCriteriaDAO;
@Inject
@Authenticated
private HAccount authenticatedAccount;
@Inject
private TextFlowTargetReviewCommentsDAO textFlowTargetReviewCommentsDAO;

@Inject
public TranslationReviewService(
TextFlowTargetDAO textFlowTargetDAO,
LocaleService localeServiceImpl,
ZanataIdentity identity,
ReviewCriteriaDAO reviewCriteriaDAO,
TextFlowTargetReviewCommentsDAO textFlowTargetReviewCommentsDAO,
@Authenticated HAccount authenticatedAccount) {

this.textFlowTargetDAO = textFlowTargetDAO;
this.localeServiceImpl = localeServiceImpl;
this.identity =identity;
this.reviewCriteriaDAO = reviewCriteriaDAO;
this.textFlowTargetReviewCommentsDAO = textFlowTargetReviewCommentsDAO;
this.authenticatedAccount = authenticatedAccount;
}

@Override
public Response put(String localeId, ReviewData data) {
public Response put(String localeId, @NotNull ReviewData data) {
if (data == null) {
return Response.status(
Response.Status.BAD_REQUEST)
.entity(Lists.newArrayList("data is invalid"))
.build();
}
HLocale locale =
localeServiceImpl.getByLocaleId(localeId);
if (locale == null) {
Expand Down
Expand Up @@ -2,6 +2,7 @@

import org.zanata.rest.editor.dto.ReviewData;

import javax.validation.constraints.NotNull;
import javax.ws.rs.Consumes;
import javax.ws.rs.PUT;
import javax.ws.rs.PathParam;
Expand Down Expand Up @@ -39,5 +40,5 @@ public interface TranslationReviewResource {
@Consumes({ MediaType.APPLICATION_JSON,
MediaType.APPLICATION_JSON })
Response put(@PathParam("localeId") String localeId,
ReviewData data);
@NotNull ReviewData data);
}
@@ -0,0 +1,67 @@
package org.zanata.rest.editor.dto;

import org.junit.Test;
import org.zanata.common.ContentState;

import static org.assertj.core.api.AssertionsForInterfaceTypes.assertThat;

/**
* @author Alex Eng <a href="mailto:aeng@redhat.com">aeng@redhat.com</a>
**/
public class ReviewDataTest {

@Test
public void transUnitIdTest() {
Long id = 10L;
ReviewData data = new ReviewData();
data.setTransUnitId(id);
assertThat(data.getTransUnitId()).isEqualTo(id);
}

@Test
public void revisionTest() {
int revision = 10;
ReviewData data = new ReviewData();
data.setRevision(revision);
assertThat(data.getRevision()).isEqualTo(revision);
}

@Test
public void commentTest() {
String comment = "comment";
ReviewData data = new ReviewData();
data.setComment(comment);
assertThat(data.getComment()).isEqualTo(comment);
}

@Test
public void criteriaIdTest() {
Long id = 10L;
ReviewData data = new ReviewData();
data.setReviewCriteriaId(id);
assertThat(data.getReviewCriteriaId()).isEqualTo(id);
}

@Test
public void statusTest() {
ContentState status = ContentState.Approved;
ReviewData data = new ReviewData();
data.setStatus(status);
assertThat(data.getStatus()).isEqualTo(status);
}

@Test
public void equalTest() {
ContentState status = ContentState.Approved;
ReviewData data = new ReviewData();
data.setStatus(status);
data.setReviewCriteriaId(1L);

ReviewData data2 = new ReviewData();
data2.setStatus(status);
data2.setReviewCriteriaId(1L);

assertThat(data).isEqualTo(data2);
assertThat(data.hashCode()).isEqualTo(data2.hashCode());
}
}

0 comments on commit 0806dcd

Please sign in to comment.