Skip to content
This repository has been archived by the owner on Nov 9, 2017. It is now read-only.

Commit

Permalink
Merge branch 'rhbz1077439' of github.com:zanata/zanata-server into rh…
Browse files Browse the repository at this point in the history
…bz1077439
  • Loading branch information
Alex Eng committed Apr 15, 2014
2 parents 997dd5b + 1db4c3e commit f7b408c
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 66 deletions.
Expand Up @@ -36,13 +36,14 @@ public void setupDatabase() throws Exception {
super.prepareDataBeforeTest();
}

public void setupEM() {
@Override
protected void setupEM() {
// do nothing
}

@BeforeMethod
@Override
public void prepareDataBeforeTest() {
protected void prepareDataBeforeTest() {
// do nothing
}

Expand All @@ -52,7 +53,8 @@ public void tearDownDatabase() {
super.shutdownEM();
}

public void shutdownEM() {
@Override
protected void shutdownEM() {
// do nothing
}

Expand Down
Expand Up @@ -74,7 +74,7 @@ protected Boolean isReplaceNull() {

@BeforeMethod
@Before
public void prepareDataBeforeTest() {
protected void prepareDataBeforeTest() {
// This is not pretty but we unfortunately can not have dependencies
// between @BeforeClass methods.
// This was a basic design mistake and we can't change it now because we
Expand Down
6 changes: 4 additions & 2 deletions zanata-war/src/test/java/org/zanata/ZanataJpaTest.java
Expand Up @@ -19,9 +19,11 @@
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.BeforeSuite;
import org.testng.annotations.Listeners;
import org.testng.annotations.Test;
import org.zanata.testng.TestMethodListener;

@Listeners(TestMethodListener.class)
@Test
public abstract class ZanataJpaTest {
private static final Logger log = LoggerFactory.getLogger(ZanataJpaTest.class);
private static final String PERSIST_NAME = "zanataTestDatasourcePU";
Expand All @@ -32,15 +34,15 @@ public abstract class ZanataJpaTest {

@BeforeMethod
@Before
public void setupEM() {
protected void setupEM() {
log.debug("Setting up EM");
em = emf.createEntityManager();
em.getTransaction().begin();
}

@AfterMethod
@After
public void shutdownEM() {
protected void shutdownEM() {
log.debug("Shutting down EM");
clearHibernateSecondLevelCache();
em.getTransaction().rollback();
Expand Down
Expand Up @@ -91,7 +91,7 @@ protected void prepareDBUnitOperations() {
}

@BeforeMethod
public void beforeMethod() throws Exception {
protected void beforeMethod() throws Exception {
seam.reset()
.use("entityManager", Search.getFullTextEntityManager(getEm()))
.use("entityManagerFactory", getEmf())
Expand Down Expand Up @@ -119,7 +119,7 @@ public void individualTest() {

// TODO most of these combinations should be tested in unit tests instead
@DataProvider(name = "CopyTrans")
public Object[][] createCopyTransTestParams() {
protected Object[][] createCopyTransTestParams() {
Set<CopyTransExecution> expandedExecutions = generateAllExecutions();

Object[][] val = new Object[expandedExecutions.size()][1];
Expand Down Expand Up @@ -311,64 +311,6 @@ public void reuseTranslationsFromObsoleteDocuments() throws Exception {
testCopyTrans(execution);
}

/**
* Makes sure that given two equal results, it will reuse the most recent
* translation.
*/
@Test
public void preferLatestTranslation() throws Exception {
ProjectIterationDAO projectIterationDAO =
seam.autowire(ProjectIterationDAO.class);
DocumentDAO documentDAO = seam.autowire(DocumentDAO.class);

HProjectIteration version =
projectIterationDAO.getBySlug("same-project", "same-version");
assert version != null;

// Create another version with translations in the same project
HProjectIteration newerVersion = new HProjectIteration();
newerVersion.setSlug("newer-version");
newerVersion.setProject(version.getProject());
projectIterationDAO.makePersistent(newerVersion);

// Duplicate the documents (with text flows and translations) on the
// newer version
for (HDocument doc : version.getDocuments().values()) {
HDocument newDoc =
new HDocument(doc.getDocId(), doc.getContentType(),
doc.getLocale());
newDoc.setProjectIteration(newerVersion);
newerVersion.getDocuments().put(newDoc.getPath(), newDoc);

for (HTextFlow tf : doc.getTextFlows()) {
HTextFlow newTf =
new HTextFlow(newDoc, tf.getResId(), tf.getContents()
.get(0));

for (HTextFlowTarget tft : tf.getTargets().values()) {
HTextFlowTarget newTft =
new HTextFlowTarget(newTf, tft.getLocale());
newTft.setContent0(tft.getContents().get(0) + " recent");
newTft.setState(Translated);
newTf.getTargets().put(newTft.getLocale().getId(), newTft);
}
newDoc.getTextFlows().add(newTf);
}
documentDAO.makePersistent(newDoc);
}

getEm().flush();
// force flushing of index in h2
Search.getFullTextEntityManager(getEm()).flushToIndexes();

// run copy trans and make sure the latest translation is copied
CopyTransExecution execution =
new CopyTransExecution(IGNORE, IGNORE, IGNORE, true, true,
true, true, Approved).expectTransState(Translated)
.withContents("target-content-de recent");
testCopyTrans(execution);
}

private ContentState getExpectedContentState(CopyTransExecution execution) {
ContentState expectedContentState =
execution.getRequireTranslationReview() ? Approved : Translated;
Expand Down

0 comments on commit f7b408c

Please sign in to comment.