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

Commit

Permalink
Move and simplify tests from CopyTransServiceImplTest to TranslationF…
Browse files Browse the repository at this point in the history
…inderTest

Remove CopyTransServiceImplTest combinations which are tested by
TranslationFinderTest
  • Loading branch information
seanf committed Apr 24, 2014
1 parent 475fde4 commit 7584ef4
Show file tree
Hide file tree
Showing 4 changed files with 257 additions and 59 deletions.
Expand Up @@ -65,10 +65,12 @@
import static org.zanata.model.HCopyTransOptions.ConditionRuleAction.DOWNGRADE_TO_FUZZY;
import static org.zanata.model.HCopyTransOptions.ConditionRuleAction.IGNORE;
import static org.zanata.model.HCopyTransOptions.ConditionRuleAction.REJECT;
import static org.zanata.service.impl.ExecutionHelper.cartesianProduct;

/**
* @author Carlos Munoz <a
* href="mailto:camunoz@redhat.com">camunoz@redhat.com</a>
* @author Sean Flanigan <a href="mailto:sflaniga@redhat.com">sflaniga@redhat.com</a>
*/
@Test(groups = { "business-tests" })
public class CopyTransServiceImplTest extends ZanataDbunitJpaTest {
Expand Down Expand Up @@ -117,12 +119,9 @@ public void individualTest() {
.expectTransState(NeedReview));
}

// TODO move most of the cases into TranslationMemoryServiceImplTest
// FIXME cut down the number of executions, and remove the 'indices' param
// NB: Reduced because it otherwise takes about 25 minutes
@DataProvider(name = "CopyTrans", indices = {0,1,2,3,4,5,6,7,8})
@DataProvider(name = "CopyTrans")
protected Object[][] createCopyTransTestParams() {
Set<CopyTransExecution> expandedExecutions = generateAllExecutions();
Set<CopyTransExecution> expandedExecutions = generateExecutions();

Object[][] val = new Object[expandedExecutions.size()][1];
int i = 0;
Expand Down Expand Up @@ -170,7 +169,7 @@ public void testCopyTrans(CopyTransExecution execution) {
// Create the document
HDocument doc = new HDocument();
doc.setContentType(ContentType.TextPlain);
doc.setLocale(localeDAO.findByLocaleId(new LocaleId("en-US")));
doc.setLocale(localeDAO.findByLocaleId(LocaleId.EN_US));
doc.setProjectIteration(projectIteration);
if (execution.documentMatches) {
doc.setFullPath("/same/document");
Expand Down Expand Up @@ -213,10 +212,8 @@ public void testCopyTrans(CopyTransExecution execution) {
.setParameter("docId", doc.getDocId())
.setParameter("resId", textFlow.getResId())
.getSingleResult();
HTextFlowTarget target = targetTextFlow.getTargets().get(3L); // Id: 3
// for
// Locale
// de
// Id: 3L for Locale de
HTextFlowTarget target = targetTextFlow.getTargets().get(3L);

if (execution.isExpectUntranslated()) {
if (target != null && target.getState() != ContentState.New) {
Expand Down Expand Up @@ -305,8 +302,7 @@ public void reuseTranslationsFromObsoleteDocuments() throws Exception {
}
}

// Run the copy trans scenario (very liberal, but nothing should be
// translated)
// Run the copy trans scenario
CopyTransExecution execution =
new CopyTransExecution(IGNORE, IGNORE, IGNORE, true, true,
true, true, Approved).expectTransState(Approved);
Expand Down Expand Up @@ -346,15 +342,16 @@ private static ContentState getExpectedContentState(boolean match,
}
}

private Set<CopyTransExecution> generateAllExecutions() {
private Set<CopyTransExecution> generateExecutions() {
Set<CopyTransExecution> allExecutions =
new HashSet<CopyTransExecution>();
// NB combinations which affect the query parameters
// (context match/mismatch, etc) are tested in TranslationFinderTest
Set<Object[]> paramsSet =
cartesianProduct(Arrays.asList(ConditionRuleAction.values()),
Arrays.asList(ConditionRuleAction.values()),
Arrays.asList(ConditionRuleAction.values()),
Arrays.asList(true, false), Arrays.asList(true, false),
Arrays.asList(true, false), Arrays.asList(true, false),
cartesianProduct(Arrays.asList(REJECT),
Arrays.asList(REJECT), Arrays.asList(REJECT),
Arrays.asList(true), Arrays.asList(true),
Arrays.asList(true), Arrays.asList(true, false),
Arrays.asList(Translated, Approved));

for (Object[] params : paramsSet) {
Expand All @@ -379,41 +376,6 @@ private Set<CopyTransExecution> generateAllExecutions() {
return allExecutions;
}

/**
* Utility method to generate a cartesian product of all possible scenarios
*/
private Set<Object[]> cartesianProduct(Iterable<?>... colls) {
// Base case
if (colls.length == 1) {
Iterable<?> lastSet = colls[0];
Set<Object[]> product = new HashSet<Object[]>();

for (Object elem : lastSet) {
product.add(new Object[] { elem });
}
return product;
}
// Recursive case
else {
Iterable<?> lastSet = colls[colls.length - 1];
Set<Object[]> subProduct =
cartesianProduct(Arrays.copyOfRange(colls, 0,
colls.length - 1));
Set<Object[]> fullProduct = new HashSet<Object[]>();

for (Object[] subProdElem : subProduct) {
for (Object elem : lastSet) {
Object[] newSubProd =
Arrays.copyOf(subProdElem, subProdElem.length + 1);
newSubProd[newSubProd.length - 1] = elem;
fullProduct.add(newSubProd);
}
}

return fullProduct;
}
}

@Getter
@Setter
@EqualsAndHashCode
Expand Down Expand Up @@ -469,6 +431,7 @@ public CopyTransExecution withContents(String... contents) {
return this;
}

// TODO do we still want this?
public Collection<CopyTransExecution> expand() {
Set<CopyTransExecution> expanded =
new HashSet<CopyTransExecution>();
Expand Down
@@ -0,0 +1,68 @@
/*
* 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.service.impl;

import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;

/**
* @author Carlos Munoz <a
* href="mailto:camunoz@redhat.com">camunoz@redhat.com</a>
*/
class ExecutionHelper {

/**
* Utility method to generate a cartesian product of all possible scenarios
*/
static Set<Object[]> cartesianProduct(Iterable<?>... colls) {
// Base case
if (colls.length == 1) {
Iterable<?> lastSet = colls[0];
Set<Object[]> product = new HashSet<Object[]>();

for (Object elem : lastSet) {
product.add(new Object[] { elem });
}
return product;
}
// Recursive case
else {
Iterable<?> lastSet = colls[colls.length - 1];
Set<Object[]> subProduct =
cartesianProduct(Arrays.copyOfRange(colls, 0,
colls.length - 1));
Set<Object[]> fullProduct = new HashSet<Object[]>();

for (Object[] subProdElem : subProduct) {
for (Object elem : lastSet) {
Object[] newSubProd =
Arrays.copyOf(subProdElem, subProdElem.length + 1);
newSubProd[newSubProd.length - 1] = elem;
fullProduct.add(newSubProd);
}
}

return fullProduct;
}
}

}

0 comments on commit 7584ef4

Please sign in to comment.