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 d4bd248 + c02a26b commit 3b90ea2
Show file tree
Hide file tree
Showing 4 changed files with 131 additions and 78 deletions.
65 changes: 65 additions & 0 deletions zanata-war/src/test/java/org/zanata/ImmutableDbunitJpaTest.java
@@ -0,0 +1,65 @@
/*
* Copyright 2014, Red Hat, Inc. and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.zanata;

import org.testng.annotations.AfterClass;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.BeforeMethod;

/**
* @author Sean Flanigan <a href="mailto:sflaniga@redhat.com">sflaniga@redhat.com</a>
*/
public abstract class ImmutableDbunitJpaTest extends ZanataDbunitJpaTest {

@BeforeClass
public void setupDatabase() throws Exception {
super.setupEM();
super.prepareDataBeforeTest();
}

public void setupEM() {
// do nothing
}

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

@AfterClass
public void tearDownDatabase() {
super.cleanDataAfterTest();
super.shutdownEM();
}

public void shutdownEM() {
// do nothing
}

@AfterMethod
@Override
public void cleanDataAfterTest() {
// do nothing
}

}
2 changes: 0 additions & 2 deletions zanata-war/src/test/java/org/zanata/ZanataJpaTest.java
Expand Up @@ -19,11 +19,9 @@
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(groups = { "jpa-tests" })
public abstract class ZanataJpaTest {
private static final Logger log = LoggerFactory.getLogger(ZanataJpaTest.class);
private static final String PERSIST_NAME = "zanataTestDatasourcePU";
Expand Down
Expand Up @@ -5,18 +5,15 @@

import org.assertj.core.api.Condition;
import org.dbunit.operation.DatabaseOperation;
import org.hamcrest.MatcherAssert;
import org.hamcrest.Matchers;
import org.hibernate.search.impl.FullTextSessionImpl;
import org.hibernate.search.jpa.Search;
import org.mockito.MockitoAnnotations;
import org.testng.annotations.BeforeMethod;
import org.testng.Assert;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
import org.zanata.ZanataDbunitJpaTest;
import org.zanata.common.ContentState;
import org.zanata.ImmutableDbunitJpaTest;
import org.zanata.common.LocaleId;
import org.zanata.dao.DocumentDAO;
import org.zanata.dao.LocaleDAO;
import org.zanata.dao.ProjectIterationDAO;
import org.zanata.dao.TextFlowDAO;
Expand All @@ -32,36 +29,26 @@
import org.zanata.model.po.HPotEntryData;
import org.zanata.seam.SeamAutowire;
import org.zanata.service.SearchIndexManager;
import org.zanata.service.TranslationService;
import org.zanata.webtrans.shared.model.TransMemoryDetails;
import org.zanata.webtrans.shared.model.TransMemoryQuery;
import org.zanata.webtrans.shared.model.TransMemoryResultItem;
import org.zanata.webtrans.shared.model.TransUnitUpdateRequest;
import org.zanata.webtrans.shared.rpc.HasSearchType;
import org.zanata.webtrans.shared.rpc.TransMemoryMerge;

import com.google.common.base.Optional;
import com.google.common.collect.Lists;

import lombok.AllArgsConstructor;
import lombok.Getter;
import net.customware.gwt.dispatch.shared.ActionException;

import static com.google.common.collect.Lists.newArrayList;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Matchers.same;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import static org.zanata.common.ContentState.Approved;
import static org.zanata.common.ContentState.Translated;
import static org.zanata.model.HCopyTransOptions.ConditionRuleAction.IGNORE;
import static org.zanata.service.SecurityService.TranslationAction.MODIFY;

/**
* @author Alex Eng <a href="mailto:aeng@redhat.com">aeng@redhat.com</a>
*/
@Test(groups = { "business-tests" })
public class TranslationMemoryServiceImplTest extends ZanataDbunitJpaTest {
public class TranslationMemoryServiceImplTest extends ImmutableDbunitJpaTest {
private SeamAutowire seam = SeamAutowire.instance();
private TranslationMemoryServiceImpl service;

Expand All @@ -81,8 +68,8 @@ protected void prepareDBUnitOperations() {
DatabaseOperation.CLEAN_INSERT));
}

@BeforeMethod
public void beforeMethod() throws Exception {
@BeforeClass
public void beforeClass() throws Exception {
MockitoAnnotations.initMocks(this);
service =
seam.reset()
Expand Down Expand Up @@ -204,68 +191,21 @@ private void executeFindBestTMMatch(HTextFlow textFlow, int threshold,
public void searchBestMatchTargetTest() {
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.getDocId(), newDoc);

for (HTextFlow tf : doc.getTextFlows()) {
if (tf != null) {
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);
}
HDocument hDoc = version.getDocuments().get("/same/document0");

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

for (HDocument hDoc : version.getDocuments().values()) {
for (HTextFlow textFlow : hDoc.getTextFlows()) {
if (textFlow != null) {
for (HTextFlowTarget target : textFlow.getTargets()
.values()) {
Optional<HTextFlowTarget> match =
service.searchBestMatchTransMemory(textFlow,
target.getLocaleId(),
hDoc.getSourceLocaleId(), true, true,
true);
if (match.isPresent()) {
checkTargetContents(match.get(), "recent");
}
}
}
}
}
HTextFlow textFlow = hDoc.getTextFlows().get(0);
Optional<HTextFlowTarget> match =
service.searchBestMatchTransMemory(textFlow,
LocaleId.DE,
hDoc.getSourceLocaleId(), true, true,
true);
Assert.assertTrue(match.isPresent());
checkTargetContents(match.get(), "most recent content");
}

@Test(dataProvider = "TMData")
Expand Down Expand Up @@ -366,7 +306,8 @@ public boolean matches(List<Object> value) {

private void checkTargetContents(HTextFlowTarget target,
final String searchString) {
assertThat(target.getContents()).has(new Condition<List<String>>() {
assertThat(target.getContents()).has(
new Condition<List<String>>("contains \""+searchString+"\"") {
@Override
public boolean matches(List<String> strings) {
for (String value : strings) {
Expand Down
Expand Up @@ -145,4 +145,53 @@
slug="different-version" parentId="[NULL]"
project_id="1000" overrideLocales="TRUE" status="A" />
<HProjectIteration_Locale projectIterationId="1000" localeId="3" />

<!-- used by org.zanata.service.impl.TranslationMemoryServiceImplTest
.searchBestMatchTargetTest -->
<HProjectIteration id="102" versionNum="1"
creationDate="2009-09-01 20:30:46" lastChanged="2009-09-01 20:30:46"
slug="newer-version" parentId="[NULL]"
project_id="100" overrideLocales="FALSE"
status="A" />
<HDocument id="102" versionNum="1"
creationDate="2009-09-01 20:30:16" lastChanged="2009-09-01 20:30:16"
contentType="text/plain" docId="/same/document0"
locale="4" name="document0"
path="/same" project_iteration_id="102"
revision="1" obsolete="0" />
<HTextFlow id="112" obsolete="0" pos="0"
resId="same-context" revision="1"
document_id="102" wordCount="2"
contentHash="e0a15a5bbf6075a9ef58b8978b7b8634" plural="false"
content0="Source Content" />
<HTextFlowTarget id="103" versionNum="1"
creationDate="2009-09-02 20:30:16" lastChanged="2009-09-02 20:30:16"
locale="3" state="3" tf_id="112" tf_revision="1"
content0="newer content" />

<!-- also used by org.zanata.service.impl.TranslationMemoryServiceImplTest
.searchBestMatchTargetTest -->
<HProjectIteration id="103" versionNum="1"
creationDate="2009-09-01 20:30:46" lastChanged="2009-09-01 20:30:46"
slug="newest-version" parentId="[NULL]"
project_id="100" overrideLocales="FALSE"
status="A" />
<HDocument id="103" versionNum="1"
creationDate="2009-09-01 20:30:16" lastChanged="2009-09-01 20:30:16"
contentType="text/plain" docId="/same/document0"
locale="4" name="document0"
path="/same" project_iteration_id="103"
revision="1" obsolete="0" />
<HTextFlow id="113" obsolete="0" pos="0"
resId="same-context" revision="1"
document_id="103" wordCount="2"
contentHash="e0a15a5bbf6075a9ef58b8978b7b8634" plural="false"
content0="Source Content" />
<HTextFlowTarget id="102" versionNum="1"
creationDate="2009-09-03 20:30:16" lastChanged="2009-09-03 20:30:16"
locale="3" state="3" tf_id="113" tf_revision="1"
content0="most recent content (but not highest id)" />



</dataset>

0 comments on commit 3b90ea2

Please sign in to comment.