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 pull request #340 from zanata/functional-test-enhance
use entity manager inside jboss to create test data
- Loading branch information
Showing
14 changed files
with
584 additions
and
477 deletions.
There are no files selected for viewing
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
39 changes: 39 additions & 0 deletions
39
functional-test/src/main/java/org/zanata/rest/SampleProjectResource.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,39 @@ | ||
package org.zanata.rest; | ||
|
||
|
||
import java.util.Set; | ||
import javax.ws.rs.DELETE; | ||
import javax.ws.rs.GET; | ||
import javax.ws.rs.POST; | ||
import javax.ws.rs.PUT; | ||
import javax.ws.rs.Path; | ||
import javax.ws.rs.PathParam; | ||
import javax.ws.rs.QueryParam; | ||
import javax.ws.rs.core.Response; | ||
|
||
import org.zanata.common.LocaleId; | ||
|
||
@Path("/test/data/sample") | ||
public interface SampleProjectResource { | ||
|
||
|
||
@PUT | ||
@Path("/languages") | ||
Response makeSampleLanguages(); | ||
|
||
@PUT | ||
@Path("/accounts/u/{username}/languages") | ||
Response userJoinsLanguageTeams(@PathParam("username") String username, | ||
@QueryParam("locales") Set<LocaleId> locales); | ||
|
||
@PUT | ||
@Path("/users") | ||
Response makeSampleUsers(); | ||
|
||
@PUT | ||
@Path("/project") | ||
Response makeSampleProject(); | ||
|
||
@DELETE | ||
Response deleteExceptEssentialData(); | ||
} |
94 changes: 94 additions & 0 deletions
94
functional-test/src/main/java/org/zanata/rest/SampleProjectResourceImpl.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,94 @@ | ||
package org.zanata.rest; | ||
|
||
import java.util.List; | ||
import java.util.Set; | ||
import javax.persistence.EntityManager; | ||
import javax.ws.rs.Path; | ||
import javax.ws.rs.PathParam; | ||
import javax.ws.rs.QueryParam; | ||
import javax.ws.rs.core.Response; | ||
import org.jboss.seam.annotations.In; | ||
import org.jboss.seam.annotations.Name; | ||
import org.jboss.seam.annotations.Transactional; | ||
import org.jboss.seam.security.RunAsOperation; | ||
import org.zanata.common.LocaleId; | ||
import org.zanata.model.HLocale; | ||
import org.zanata.model.HPerson; | ||
import org.zanata.util.SampleProjectProfile; | ||
|
||
/** | ||
* @author Patrick Huang <a | ||
* href="mailto:pahuang@redhat.com">pahuang@redhat.com</a> | ||
*/ | ||
@Path("/test/data/sample") | ||
@Name("sampleProjectResourceImpl") | ||
public class SampleProjectResourceImpl implements SampleProjectResource { | ||
|
||
@In(create = true) | ||
private SampleProjectProfile sampleProjectProfile; | ||
|
||
@In | ||
private EntityManager entityManager; | ||
|
||
@Override | ||
public Response makeSampleLanguages() { | ||
new RunAsOperation() { | ||
@Override | ||
public void execute() { | ||
sampleProjectProfile.makeSampleLanguages(); | ||
} | ||
}.addRole("admin").run(); | ||
return Response.ok().build(); | ||
} | ||
|
||
@Override | ||
public Response makeSampleUsers() { | ||
new RunAsOperation() { | ||
public void execute() { | ||
sampleProjectProfile.makeSampleUsers(); | ||
} | ||
}.addRole("admin").run(); | ||
return Response.ok().build(); | ||
} | ||
|
||
@Override | ||
@Transactional | ||
public Response userJoinsLanguageTeams( | ||
@PathParam("username") String username, | ||
@QueryParam("locales") Set<LocaleId> locales) { | ||
|
||
|
||
final HPerson hPerson = entityManager | ||
.createQuery("from HPerson p where p.account.username = :username", | ||
HPerson.class).setParameter("username", username).getSingleResult(); | ||
final List<HLocale> hLocales = entityManager | ||
.createQuery("from HLocale where localeId in (:locales)", | ||
HLocale.class).setParameter("locales", locales).getResultList(); | ||
new RunAsOperation() { | ||
public void execute() { | ||
sampleProjectProfile.addUsersToLanguage(hPerson, hLocales); | ||
} | ||
}.addRole("admin").run(); | ||
return Response.ok().build(); | ||
} | ||
|
||
@Override | ||
public Response makeSampleProject() { | ||
new RunAsOperation() { | ||
public void execute() { | ||
sampleProjectProfile.makeSampleProject(); | ||
} | ||
}.addRole("admin").run(); | ||
return Response.ok().build(); | ||
} | ||
|
||
@Override | ||
public Response deleteExceptEssentialData() { | ||
new RunAsOperation() { | ||
public void execute() { | ||
sampleProjectProfile.deleteExceptEssentialData(); | ||
} | ||
}.addRole("admin").run(); | ||
return Response.ok().build(); | ||
} | ||
} |
Oops, something went wrong.