Search in sources :

Example 61 with BasicEList

use of org.eclipse.emf.common.util.BasicEList in project tdq-studio-se by Talend.

the class ColumnSetIndicatorEvaluatorTest method testExecuteSqlQuery_file.

/**
 * Test method for {@link org.talend.dq.indicators.ColumnSetIndicatorEvaluator#executeSqlQuery(String)} .
 */
@Test
public void testExecuteSqlQuery_file() throws Exception {
    Analysis analysis = mock(Analysis.class);
    // $NON-NLS-1$
    stub(method(DelimitedFileIndicatorEvaluator.class, "handleByARow"));
    // $NON-NLS-1$
    stub(method(DelimitedFileIndicatorEvaluator.class, "addResultToIndicatorToRowMap", Indicator.class, EMap.class));
    AnalysisContext context = mock(AnalysisContext.class);
    when(analysis.getContext()).thenReturn(context);
    DelimitedFileConnection deliFileConn = mock(DelimitedFileConnection.class);
    when(context.getConnection()).thenReturn(deliFileConn);
    when(deliFileConn.isContextMode()).thenReturn(true);
    when(deliFileConn.getFilePath()).thenReturn(context_fd1_File);
    when(deliFileConn.getFieldSeparatorValue()).thenReturn(context_fd1_FieldSeparator);
    when(deliFileConn.getEncoding()).thenReturn(context_fd1_Encoding);
    IPath iPath = mock(IPath.class);
    File file = new File(realFile);
    BufferedWriter output = new BufferedWriter(new FileWriter(file));
    String str = "id;Cocust(Tests);owner_id\n" + "1;yellow;3301\n" + "2;blue;3302\n" + "4;red;3307\n" + "5;white;4563\n" + "6;pink2;457883\n" + "7;blank;231233\n";
    output.write(str);
    output.close();
    when(iPath.toFile()).thenReturn(file);
    assertTrue(file.exists());
    PowerMockito.mockStatic(JavaSqlFactory.class);
    when(JavaSqlFactory.getURL(deliFileConn)).thenReturn(realFile);
    when(JavaSqlFactory.getFieldSeparatorValue(deliFileConn)).thenReturn(realFieldSeparator);
    when(JavaSqlFactory.getEncoding(deliFileConn)).thenReturn(realEncoding);
    PowerMockito.mockStatic(ResourceBundle.class);
    ResourceBundle bundle = mock(ResourceBundle.class);
    // $NON-NLS-1$
    when(ResourceBundle.getBundle("Messages")).thenReturn(bundle);
    PowerMockito.mockStatic(Messages.class);
    // $NON-NLS-1$
    when(Messages.getString(anyString())).thenReturn("testString");
    AnalysisResult results = mock(AnalysisResult.class);
    when(analysis.getResults()).thenReturn(results);
    EMap<Indicator, AnalyzedDataSet> indicToRowMap = mock(EMap.class);
    when(results.getIndicToRowMap()).thenReturn(indicToRowMap);
    when(deliFileConn.getHeaderValue()).thenReturn(context_fd1_Header);
    when(deliFileConn.getFooterValue()).thenReturn(zero);
    when(deliFileConn.getLimitValue()).thenReturn(zero);
    when(deliFileConn.getEscapeType()).thenReturn(Escape.DELIMITED);
    when(deliFileConn.getRowSeparatorValue()).thenReturn(context_fd1_RowSeparator);
    when(deliFileConn.isSplitRecord()).thenReturn(false);
    when(deliFileConn.isRemoveEmptyRow()).thenReturn(false);
    when(JavaSqlFactory.getHeadValue(deliFileConn)).thenReturn(realHeading);
    when(JavaSqlFactory.getRowSeparatorValue(deliFileConn)).thenReturn(realRowSeparator);
    PowerMockito.mockStatic(LanguageManager.class);
    when(LanguageManager.getCurrentLanguage()).thenReturn(ECodeLanguage.JAVA);
    PowerMockito.mockStatic(ParameterUtil.class);
    when(ParameterUtil.trimParameter(realFile)).thenReturn(realFile);
    when(ParameterUtil.trimParameter(realEncoding)).thenReturn(realEncoding);
    PowerMockito.mockStatic(StringUtils.class);
    when(StringUtils.loadConvert(realFieldSeparator, ECodeLanguage.JAVA.getName())).thenReturn(realFieldSeparator);
    when(ParameterUtil.trimParameter(realFieldSeparator)).thenReturn(realFieldSeparator);
    when(StringUtils.loadConvert(realRowSeparator, ECodeLanguage.JAVA.getName())).thenReturn(realRowSeparator);
    when(ParameterUtil.trimParameter(realRowSeparator)).thenReturn(realRowSeparator);
    List<ModelElement> columnElementList = new BasicEList<ModelElement>();
    List<MetadataColumn> columnElementList2 = new BasicEList<MetadataColumn>();
    MetadataColumn mc0 = mock(MetadataColumn.class);
    MetadataColumn mc1 = mock(MetadataColumn.class);
    MetadataColumn mc2 = mock(MetadataColumn.class);
    columnElementList.add(mc0);
    columnElementList.add(mc1);
    columnElementList.add(mc2);
    columnElementList2.add(mc0);
    columnElementList2.add(mc1);
    columnElementList2.add(mc2);
    EList<ModelElement> eLs = (EList<ModelElement>) columnElementList;
    when(context.getAnalysedElements()).thenReturn(eLs);
    PowerMockito.mockStatic(ColumnHelper.class);
    MetadataTable mTable = mock(MetadataTable.class);
    when(mTable.getColumns()).thenReturn((EList<MetadataColumn>) columnElementList2);
    when(ColumnHelper.getColumnOwnerAsMetadataTable(mc0)).thenReturn(mTable);
    when(ColumnHelper.getColumnOwnerAsMetadataTable(mc1)).thenReturn(mTable);
    when(ColumnHelper.getColumnOwnerAsMetadataTable(mc2)).thenReturn(mTable);
    ColumnSetIndicatorEvaluator evaluator = new ColumnSetIndicatorEvaluator(analysis);
    ColumnSetIndicatorEvaluator spyEvaluator = Mockito.spy(evaluator);
    Mockito.doReturn(true).when(spyEvaluator).continueRun();
    ReturnCode rc = spyEvaluator.executeSqlQuery(empty);
    assertTrue(rc.isOk());
}
Also used : FileWriter(java.io.FileWriter) AnalysisContext(org.talend.dataquality.analysis.AnalysisContext) Matchers.anyString(org.mockito.Matchers.anyString) BufferedWriter(java.io.BufferedWriter) ModelElement(orgomg.cwm.objectmodel.core.ModelElement) MetadataColumn(org.talend.core.model.metadata.builder.connection.MetadataColumn) MetadataTable(org.talend.core.model.metadata.builder.connection.MetadataTable) ReturnCode(org.talend.utils.sugars.ReturnCode) IPath(org.eclipse.core.runtime.IPath) AnalyzedDataSet(org.talend.dataquality.analysis.AnalyzedDataSet) BasicEList(org.eclipse.emf.common.util.BasicEList) DelimitedFileConnection(org.talend.core.model.metadata.builder.connection.DelimitedFileConnection) Indicator(org.talend.dataquality.indicators.Indicator) AnalysisResult(org.talend.dataquality.analysis.AnalysisResult) BasicEList(org.eclipse.emf.common.util.BasicEList) EList(org.eclipse.emf.common.util.EList) Analysis(org.talend.dataquality.analysis.Analysis) EMap(org.eclipse.emf.common.util.EMap) ResourceBundle(java.util.ResourceBundle) File(java.io.File) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 62 with BasicEList

use of org.eclipse.emf.common.util.BasicEList in project tdq-studio-se by Talend.

the class DelimitedFileIndicatorEvaluatorTest method testExecuteSqlQuery_delimetd.

@Ignore
@Test
public void testExecuteSqlQuery_delimetd() throws Exception {
    // $NON-NLS-1$
    String empty = "";
    Analysis analysis = mock(Analysis.class);
    DelimitedFileIndicatorEvaluator delFileIndiEvaluator = new DelimitedFileIndicatorEvaluator(analysis);
    DelimitedFileIndicatorEvaluator spyEvaluator = Mockito.spy(delFileIndiEvaluator);
    // $NON-NLS-1$
    stub(method(DelimitedFileIndicatorEvaluator.class, "handleByARow"));
    // $NON-NLS-1$
    stub(method(DelimitedFileIndicatorEvaluator.class, "addResultToIndicatorToRowMap", Indicator.class, EMap.class));
    AnalysisContext context = mock(AnalysisContext.class);
    when(analysis.getContext()).thenReturn(context);
    DelimitedFileConnection deliFileConn = mock(DelimitedFileConnection.class);
    when(context.getConnection()).thenReturn(deliFileConn);
    when(deliFileConn.isContextMode()).thenReturn(false);
    // $NON-NLS-1$
    String path = "test.txt";
    PowerMockito.mockStatic(JavaSqlFactory.class);
    when(JavaSqlFactory.getURL(deliFileConn)).thenReturn(path);
    IPath iPath = mock(IPath.class);
    File file = new File(path);
    BufferedWriter output = new BufferedWriter(new FileWriter(file));
    String str = // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$
    "id;Cocust(Tests);owner_id\n" + "1;yellow;3301\n" + "2;blue;3302\n" + " 4;red;3307\n" + "5;white;4563\n" + "6;pink2;457883\n" + // $NON-NLS-1$ //$NON-NLS-2$
    "7;blank;231233\n";
    output.write(str);
    output.close();
    when(iPath.toFile()).thenReturn(file);
    // $NON-NLS-1$
    when(deliFileConn.getFieldSeparatorValue()).thenReturn(";");
    // $NON-NLS-1$
    when(deliFileConn.getEncoding()).thenReturn("US-ASCII");
    AnalysisResult results = mock(AnalysisResult.class);
    when(analysis.getResults()).thenReturn(results);
    EMap<Indicator, AnalyzedDataSet> indicToRowMap = mock(EMap.class);
    when(results.getIndicToRowMap()).thenReturn(indicToRowMap);
    List<ModelElement> columnElementList = new BasicEList<ModelElement>();
    List<MetadataColumn> columnElementList2 = new BasicEList<MetadataColumn>();
    MetadataColumn mc0 = mock(MetadataColumn.class);
    MetadataColumn mc1 = mock(MetadataColumn.class);
    MetadataColumn mc2 = mock(MetadataColumn.class);
    columnElementList.add(mc0);
    columnElementList.add(mc1);
    columnElementList.add(mc2);
    columnElementList2.add(mc0);
    columnElementList2.add(mc1);
    columnElementList2.add(mc2);
    EList<ModelElement> eLs = (EList<ModelElement>) columnElementList;
    when(context.getAnalysedElements()).thenReturn(eLs);
    PowerMockito.mockStatic(ColumnHelper.class);
    MetadataTable mTable = mock(MetadataTable.class);
    when(mTable.getColumns()).thenReturn((EList<MetadataColumn>) columnElementList2);
    when(ColumnHelper.getColumnOwnerAsMetadataTable(mc0)).thenReturn(mTable);
    when(ColumnHelper.getColumnOwnerAsMetadataTable(mc1)).thenReturn(mTable);
    when(deliFileConn.getHeaderValue()).thenReturn(empty);
    when(deliFileConn.getFooterValue()).thenReturn(empty);
    when(deliFileConn.getLimitValue()).thenReturn(empty);
    when(deliFileConn.getEscapeType()).thenReturn(Escape.DELIMITED);
    // $NON-NLS-1$
    when(deliFileConn.getRowSeparatorValue()).thenReturn("\\n");
    when(deliFileConn.isRemoveEmptyRow()).thenReturn(false);
    when(deliFileConn.isSplitRecord()).thenReturn(false);
    PowerMockito.mockStatic(LanguageManager.class);
    when(LanguageManager.getCurrentLanguage()).thenReturn(ECodeLanguage.JAVA);
    Mockito.doReturn(true).when(spyEvaluator).continueRun();
    spyEvaluator.executeSqlQuery(empty);
}
Also used : IPath(org.eclipse.core.runtime.IPath) AnalyzedDataSet(org.talend.dataquality.analysis.AnalyzedDataSet) FileWriter(java.io.FileWriter) BasicEList(org.eclipse.emf.common.util.BasicEList) DelimitedFileConnection(org.talend.core.model.metadata.builder.connection.DelimitedFileConnection) AnalysisContext(org.talend.dataquality.analysis.AnalysisContext) Indicator(org.talend.dataquality.indicators.Indicator) AnalysisResult(org.talend.dataquality.analysis.AnalysisResult) BufferedWriter(java.io.BufferedWriter) ModelElement(orgomg.cwm.objectmodel.core.ModelElement) MetadataColumn(org.talend.core.model.metadata.builder.connection.MetadataColumn) BasicEList(org.eclipse.emf.common.util.BasicEList) EList(org.eclipse.emf.common.util.EList) Analysis(org.talend.dataquality.analysis.Analysis) EMap(org.eclipse.emf.common.util.EMap) MetadataTable(org.talend.core.model.metadata.builder.connection.MetadataTable) File(java.io.File) Ignore(org.junit.Ignore) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 63 with BasicEList

use of org.eclipse.emf.common.util.BasicEList in project tdq-studio-se by Talend.

the class IndicatorDefinitionFileHelperTest method setup.

@Before
public void setup() {
    indiDefinition = DefinitionFactoryImpl.eINSTANCE.createIndicatorDefinition();
    EList<TdExpression> tdExpessionLs = new BasicEList<TdExpression>();
    TdExpression tdExpression1 = // $NON-NLS-1$
    BooleanExpressionHelper.createTdExpression(// $NON-NLS-1$
    "MySql", // $NON-NLS-1$
    "SELECT SUM(CHAR_LENGTH(<%=__COLUMN_NAMES__%>)), COUNT(<%=__COLUMN_NAMES__%>) FROM <%=__TABLE_NAME__%>");
    TdExpression tdExpression2 = BooleanExpressionHelper.createTdExpression(// $NON-NLS-1$
    "DB2", // $NON-NLS-1$
    "SELECT SUM(LENGTH(<%=__COLUMN_NAMES__%>)), COUNT(<%=__COLUMN_NAMES__%>) FROM <%=__TABLE_NAME__%> <%=__WHERE_CLAUSE__%>");
    tdExpessionLs.add(tdExpression1);
    tdExpessionLs.add(tdExpression2);
    indiDefinition.getSqlGenericExpression().add(tdExpression1);
    indiDefinition.getSqlGenericExpression().add(tdExpression2);
    UnitTestBuildHelper.initProjectStructure();
}
Also used : TdExpression(org.talend.cwm.relational.TdExpression) BasicEList(org.eclipse.emf.common.util.BasicEList) Before(org.junit.Before)

Example 64 with BasicEList

use of org.eclipse.emf.common.util.BasicEList in project smarthome by eclipse.

the class WebAppServlet method service.

@Override
public void service(ServletRequest req, ServletResponse res) throws ServletException, IOException {
    logger.debug("Servlet request received!");
    // read request parameters
    String sitemapName = req.getParameter("sitemap");
    String widgetId = req.getParameter("w");
    boolean async = "true".equalsIgnoreCase(req.getParameter("__async"));
    boolean poll = "true".equalsIgnoreCase(req.getParameter("poll"));
    // if there are no parameters, display the "default" sitemap
    if (sitemapName == null) {
        sitemapName = config.getDefaultSitemap();
    }
    StringBuilder result = new StringBuilder();
    Sitemap sitemap = null;
    for (SitemapProvider sitemapProvider : sitemapProviders) {
        sitemap = sitemapProvider.getSitemap(sitemapName);
        if (sitemap != null) {
            break;
        }
    }
    try {
        if (sitemap == null) {
            throw new RenderException("Sitemap '" + sitemapName + "' could not be found");
        }
        logger.debug("reading sitemap {} widgetId {} async {} poll {}", sitemap.getName(), widgetId, async, poll);
        if (widgetId == null || widgetId.isEmpty() || widgetId.equals("Home")) {
            // we are at the homepage, so we render the children of the sitemap root node
            String label = sitemap.getLabel() != null ? sitemap.getLabel() : sitemapName;
            EList<Widget> children = renderer.getItemUIRegistry().getChildren(sitemap);
            if (poll && waitForChanges(children) == false) {
                // we have reached the timeout, so we do not return any content as nothing has changed
                res.getWriter().append(getTimeoutResponse()).close();
                return;
            }
            result.append(renderer.processPage("Home", sitemapName, label, children, async));
        } else if (!widgetId.equals("Colorpicker")) {
            // we are on some subpage, so we have to render the children of the widget that has been selected
            Widget w = renderer.getItemUIRegistry().getWidget(sitemap, widgetId);
            if (w != null) {
                if (!(w instanceof LinkableWidget)) {
                    throw new RenderException("Widget '" + w + "' can not have any content");
                }
                LinkableWidget lw = (LinkableWidget) w;
                EList<Widget> children = renderer.getItemUIRegistry().getChildren(lw);
                EList<Widget> parentAndChildren = new BasicEList<Widget>();
                parentAndChildren.add(lw);
                parentAndChildren.addAll(children);
                if (poll && waitForChanges(parentAndChildren) == false) {
                    // we have reached the timeout, so we do not return any content as nothing has changed
                    res.getWriter().append(getTimeoutResponse()).close();
                    return;
                }
                String label = renderer.getItemUIRegistry().getLabel(w);
                if (label == null) {
                    label = "undefined";
                }
                result.append(renderer.processPage(renderer.getItemUIRegistry().getWidgetId(w), sitemapName, label, children, async));
            }
        }
    } catch (RenderException e) {
        throw new ServletException(e.getMessage(), e);
    }
    if (async) {
        res.setContentType("application/xml;charset=UTF-8");
    } else {
        res.setContentType("text/html;charset=UTF-8");
    }
    res.getWriter().append(result);
    res.getWriter().close();
}
Also used : LinkableWidget(org.eclipse.smarthome.model.sitemap.LinkableWidget) ServletException(javax.servlet.ServletException) Sitemap(org.eclipse.smarthome.model.sitemap.Sitemap) RenderException(org.eclipse.smarthome.ui.classic.render.RenderException) BasicEList(org.eclipse.emf.common.util.BasicEList) EList(org.eclipse.emf.common.util.EList) SitemapProvider(org.eclipse.smarthome.model.sitemap.SitemapProvider) Widget(org.eclipse.smarthome.model.sitemap.Widget) LinkableWidget(org.eclipse.smarthome.model.sitemap.LinkableWidget)

Example 65 with BasicEList

use of org.eclipse.emf.common.util.BasicEList in project alisa-examples by osate.

the class ModelVerifications method samePowerBudget.

public static boolean samePowerBudget(ComponentInstance ci) {
    EList<FeatureInstance> inlets = new BasicEList<FeatureInstance>();
    for (FeatureInstance fi : ci.getAllFeatureInstances(FeatureCategory.ABSTRACT_FEATURE)) {
        Classifier cl = fi.getFeature().getAllClassifier();
        if (cl.getName().equalsIgnoreCase("power")) {
            inlets.add(fi);
        }
    }
    if (inlets.size() == 2) {
        double pb1 = GetProperties.getPowerBudget(inlets.get(0), 0.0);
        double pb2 = GetProperties.getPowerBudget(inlets.get(1), 0.0);
        return pb1 == pb2;
    }
    return false;
}
Also used : FeatureInstance(org.osate.aadl2.instance.FeatureInstance) BasicEList(org.eclipse.emf.common.util.BasicEList) Classifier(org.osate.aadl2.Classifier)

Aggregations

BasicEList (org.eclipse.emf.common.util.BasicEList)75 Test (org.junit.Test)25 AdapterFactoryLabelProvider (org.eclipse.emf.edit.ui.provider.AdapterFactoryLabelProvider)16 IPropertiesEditionEvent (org.eclipse.emf.eef.runtime.api.notify.IPropertiesEditionEvent)16 PropertiesEditionEvent (org.eclipse.emf.eef.runtime.impl.notify.PropertiesEditionEvent)16 EEFFeatureEditorDialog (org.eclipse.emf.eef.runtime.ui.widgets.EEFFeatureEditorDialog)16 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)16 SelectionEvent (org.eclipse.swt.events.SelectionEvent)16 GridData (org.eclipse.swt.layout.GridData)16 TdExpression (org.talend.cwm.relational.TdExpression)11 EObject (org.eclipse.emf.ecore.EObject)10 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)9 IndicatorDefinition (org.talend.dataquality.indicators.definition.IndicatorDefinition)9 UDIndicatorDefinition (org.talend.dataquality.indicators.definition.userdefine.UDIndicatorDefinition)9 ProductVersion (org.talend.utils.ProductVersion)9 Button (org.eclipse.swt.widgets.Button)8 MetadataColumn (org.talend.core.model.metadata.builder.connection.MetadataColumn)6 ModelElement (orgomg.cwm.objectmodel.core.ModelElement)6 EStructuralFeature (org.eclipse.emf.ecore.EStructuralFeature)5 Widget (org.eclipse.smarthome.model.sitemap.Widget)5