use of org.talend.dataquality.properties.TDQPatternItem in project tdq-studio-se by Talend.
the class AElementPersistanceRealTest method testCreateItemPattern.
/**
* Test method for
* {@link org.talend.dq.writer.AElementPersistance#createItem(orgomg.cwm.objectmodel.core.ModelElement)}.
*/
@Test
public void testCreateItemPattern() {
PatternWriter createPatternWriter = ElementWriterFactory.getInstance().createPatternWriter();
// test normal name
// $NON-NLS-1$
String patternName = "pattern1";
// $NON-NLS-1$
String exceptedFileName = patternName + "_0.1.pattern";
Pattern createPattern = PatternFactory.eINSTANCE.createPattern();
createPattern.setName(patternName);
Item createItem = createPatternWriter.createItem(createPattern);
assertTrue(createItem instanceof TDQPatternItem);
TDQPatternItem patternItem = (TDQPatternItem) createItem;
assertTrue(patternItem.getFilename().equals(exceptedFileName));
// test special name
// $NON-NLS-1$
String patternName2 = "pattern1(),。";
// $NON-NLS-1$
String exceptedFileName2 = "pattern1_____0.1.pattern";
Pattern createPattern2 = PatternFactory.eINSTANCE.createPattern();
createPattern2.setName(patternName2);
Item createItem2 = createPatternWriter.createItem(createPattern2);
assertTrue(createItem2 instanceof TDQPatternItem);
TDQPatternItem patternItem2 = (TDQPatternItem) createItem2;
assertTrue(patternItem2.getFilename().equals(exceptedFileName2));
}
use of org.talend.dataquality.properties.TDQPatternItem in project tdq-studio-se by Talend.
the class FileSystemImportWriterTest method testMergePattern.
/**
* Test method for
* {@link org.talend.dataprofiler.core.ui.imex.model.FileSystemImportWriter#mergePattern(org.talend.dataprofiler.core.ui.imex.model.ItemRecord, org.talend.dataquality.domain.pattern.Pattern)}
* .
*
* @throws MalformedURLException
*/
@Test
public void testMergePattern() throws MalformedURLException {
// import object
ItemRecord importItem = mock(ItemRecord.class);
Pattern importPattern = mock(Pattern.class);
when(importItem.getElement()).thenReturn(importPattern);
// old object
TDQPatternItem oldPatternItem = mock(TDQPatternItem.class);
Pattern oldPattern = mock(Pattern.class);
when(oldPatternItem.getPattern()).thenReturn(oldPattern);
// for imported pattern's expression
InternalEObject eo = mock(InternalEObject.class);
EList<PatternComponent> importComponents = new EObjectContainmentEList<PatternComponent>(PatternComponent.class, eo, PatternPackage.PATTERN__COMPONENTS);
RegularExpression re = PatternFactory.eINSTANCE.createRegularExpression();
TdExpression td = RelationalFactory.eINSTANCE.createTdExpression();
// $NON-NLS-1$
td.setBody("sql body");
// $NON-NLS-1$
td.setLanguage("SQL");
// $NON-NLS-1$
td.setModificationDate("20130101");
re.setExpression(td);
importComponents.add(re);
RegularExpression re3 = PatternFactory.eINSTANCE.createRegularExpression();
TdExpression td3 = RelationalFactory.eINSTANCE.createTdExpression();
// $NON-NLS-1$
td3.setBody("imported body");
// $NON-NLS-1$
td3.setLanguage("MYSQL");
// $NON-NLS-1$
td3.setModificationDate("20130101");
re3.setExpression(td3);
importComponents.add(re3);
RegularExpression re4 = PatternFactory.eINSTANCE.createRegularExpression();
TdExpression td4 = RelationalFactory.eINSTANCE.createTdExpression();
// $NON-NLS-1$
td4.setBody("imported 4 body");
// $NON-NLS-1$
td4.setLanguage("Default");
td4.setModificationDate(null);
re4.setExpression(td4);
importComponents.add(re4);
when(importPattern.getComponents()).thenReturn(importComponents);
// for imported pattern's supplierDependencies
Analysis analysis = mock(Analysis.class);
Dependency dependency = mock(Dependency.class);
when(dependency.getKind()).thenReturn(DependenciesHandler.USAGE);
EList<ModelElement> analysisList = new BasicEList<ModelElement>();
analysisList.add(analysis);
when(dependency.getClient()).thenReturn(analysisList);
when(analysis.eIsProxy()).thenReturn(false);
// $NON-NLS-1$
File file = new File("C://Users//msjian//Desktop//myusetest//AA//TDQ_Data Profiling//Analyses//k_0.1.ana");
org.eclipse.emf.common.util.URI uri = URI.createFileURI(file.toURL().getPath().substring(1));
Resource resource = mock(Resource.class);
when(analysis.eResource()).thenReturn(resource);
when(resource.getURI()).thenReturn(uri);
PowerMockito.mockStatic(ResourceManager.class);
IProject pro = mock(IProject.class);
when(ResourceManager.getRootProject()).thenReturn(pro);
// $NON-NLS-1$
when(pro.getLocation()).thenReturn(new Path("D:\\worspace\\workspace_TDQEE_5.3\\A"));
EList<ModelElement> patternlist = mock(EObjectContainmentEList.class);
patternlist.add(importPattern);
when(dependency.getSupplier()).thenReturn(patternlist);
EList<Dependency> supplierDependencies_old = new BasicEList<Dependency>();
when(oldPattern.getSupplierDependency()).thenReturn(supplierDependencies_old);
Assert.assertEquals(0, oldPattern.getSupplierDependency().size());
EList<Dependency> supplierDependencies_import = new BasicEList<Dependency>();
supplierDependencies_import.add(dependency);
when(importPattern.getSupplierDependency()).thenReturn(supplierDependencies_import);
Assert.assertEquals(1, importPattern.getSupplierDependency().size());
PowerMockito.mockStatic(DependenciesHandler.class);
DependenciesHandler instance = mock(DependenciesHandler.class);
when(DependenciesHandler.getInstance()).thenReturn(instance);
TypedReturnCode<Dependency> rc = new TypedReturnCode<Dependency>();
rc.setObject(dependency);
when(instance.setUsageDependencyOn(analysis, oldPattern)).thenReturn(rc);
when(oldPattern.getSupplierDependency()).thenReturn(supplierDependencies_import);
// for system pattern's expression
EList<PatternComponent> components = new EObjectContainmentEList<PatternComponent>(PatternComponent.class, eo, PatternPackage.PATTERN__COMPONENTS);
RegularExpression re2 = PatternFactory.eINSTANCE.createRegularExpression();
TdExpression td2 = RelationalFactory.eINSTANCE.createTdExpression();
// $NON-NLS-1$
td2.setBody("system 2 body");
// $NON-NLS-1$
td2.setLanguage("MYSQL");
// $NON-NLS-1$
td2.setModificationDate("20120101");
re2.setExpression(td2);
components.add(re2);
// for re5: should be replace by re4
RegularExpression re5 = PatternFactory.eINSTANCE.createRegularExpression();
TdExpression td5 = RelationalFactory.eINSTANCE.createTdExpression();
// $NON-NLS-1$
td5.setBody("system 5 body");
// $NON-NLS-1$
td5.setLanguage("Default");
td5.setModificationDate(null);
re5.setExpression(td5);
components.add(re5);
when(oldPattern.getComponents()).thenReturn(components);
ElementWriterFactory ewFactory = mock(ElementWriterFactory.class);
PatternWriter pw = mock(PatternWriter.class);
when(pw.save(oldPatternItem, true)).thenReturn(null);
// $NON-NLS-1$
stub(method(ElementWriterFactory.class, "getInstance")).toReturn(ewFactory);
when(ewFactory.createPatternWriter()).thenReturn(pw);
writer.mergePattern(importItem, oldPatternItem);
for (PatternComponent component : components) {
TdExpression ex = ((RegularExpression) component).getExpression();
if (ex.getLanguage().equals("SQL")) {
// $NON-NLS-1$
// $NON-NLS-1$
Assert.assertEquals("sql body", ex.getBody());
} else if (ex.getLanguage().equals("MYSQL")) {
// $NON-NLS-1$
// $NON-NLS-1$
Assert.assertEquals("imported body", ex.getBody());
} else if (ex.getLanguage().equals("Default")) {
// $NON-NLS-1$
// $NON-NLS-1$
Assert.assertEquals("imported 4 body", ex.getBody());
}
}
Assert.assertNotNull(oldPattern.getSupplierDependency());
Assert.assertEquals(1, oldPattern.getSupplierDependency().size());
}
use of org.talend.dataquality.properties.TDQPatternItem in project tdq-studio-se by Talend.
the class PropertyHelper method getModelElement.
/**
* DOC bZhou Comment method "getModelElement".
*
* Get model element from property recognized by current system.
*
* @param property
* @return
*/
public static ModelElement getModelElement(Property property) {
Item item = property.getItem();
assert item != null;
ModelElement element = (ModelElement) new org.talend.core.model.properties.util.PropertiesSwitch() {
@Override
public Object caseDatabaseConnectionItem(DatabaseConnectionItem object) {
return object.getConnection();
}
@Override
public Object caseMDMConnectionItem(MDMConnectionItem object) {
return object.getConnection();
}
@Override
public Object caseDelimitedFileConnectionItem(DelimitedFileConnectionItem object) {
return object.getConnection();
}
}.doSwitch(item);
if (element == null) {
element = new org.talend.dataquality.properties.util.PropertiesSwitch<ModelElement>() {
@Override
public ModelElement caseTDQReportItem(TDQReportItem object) {
return object.getReport();
}
@Override
public ModelElement caseTDQAnalysisItem(TDQAnalysisItem object) {
return object.getAnalysis();
}
@Override
public ModelElement caseTDQBusinessRuleItem(TDQBusinessRuleItem object) {
return object.getDqrule();
}
/*
* (non-Javadoc)
*
* @see
* org.talend.dataquality.properties.util.PropertiesSwitch#caseTDQMatchRuleItem(org.talend.dataquality
* .properties.TDQMatchRuleItem)
*/
@Override
public ModelElement caseTDQMatchRuleItem(TDQMatchRuleItem object) {
return object.getMatchRule();
}
@Override
public ModelElement caseTDQIndicatorDefinitionItem(TDQIndicatorDefinitionItem object) {
return object.getIndicatorDefinition();
}
@Override
public ModelElement caseTDQPatternItem(TDQPatternItem object) {
return object.getPattern();
}
}.doSwitch(item);
}
return element;
}
use of org.talend.dataquality.properties.TDQPatternItem in project tdq-studio-se by Talend.
the class RespositoryDetailView method createTechnicalDetail.
private void createTechnicalDetail(IRepositoryViewObject reposViewObj) {
// MOD klliu the DQRepositoryview unified with tos, so refactor as follow bug 19154 2011-02-28
if (reposViewObj.getProperty() != null) {
Item item = reposViewObj.getProperty().getItem();
if (item instanceof ConnectionItem) {
Connection conn = ((ConnectionItem) item).getConnection();
createTechnicalDetail(conn);
} else if (item instanceof TDQAnalysisItem) {
Analysis analysis = ((TDQAnalysisItem) item).getAnalysis();
createTechnicalDetail(analysis);
} else if (item instanceof TDQPatternItem) {
Pattern pattern = ((TDQPatternItem) item).getPattern();
createTechnicalDetail(pattern);
} else if (item instanceof TDQReportItem) {
Report report = ((TDQReportItem) item).getReport();
createTechnicalDetail(report);
}
}
}
use of org.talend.dataquality.properties.TDQPatternItem in project tdq-studio-se by Talend.
the class PatternRepNode method getChildren.
@Override
public List<IRepositoryNode> getChildren() {
List<IRepositoryNode> languageElement = new ArrayList<IRepositoryNode>();
IRepositoryViewObject object = this.getObject();
TDQPatternItem patternItem = (TDQPatternItem) object.getProperty().getItem();
Pattern pattern = patternItem.getPattern();
EList<PatternComponent> components = pattern.getComponents();
for (PatternComponent component : components) {
RegularExpression re = (RegularExpression) component;
Expression expression = re.getExpression();
String language = expression.getLanguage();
PatternLanguageRepNode plrn = new PatternLanguageRepNode(this, ENodeType.TDQ_REPOSITORY_ELEMENT, getProject());
plrn.setRegularExpression(re);
plrn.setId(language);
plrn.setLabel(language);
languageElement.add(plrn);
}
// MOD gdbu 2011-7-11 bug : 22204
return filterResultsIfAny(languageElement);
// ~22204
}
Aggregations