Revision 46507 trunk/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.dal/org.gvsig.fmap.dal.db/org.gvsig.fmap.dal.db.jdbc/src/test/java/org/gvsig/fmap/dal/store/jdbc2/AbstractTestUtils.java

View differences:

AbstractTestUtils.java
14 14
import org.apache.commons.lang3.BooleanUtils;
15 15
import org.apache.commons.lang3.StringUtils;
16 16
import org.apache.commons.lang3.math.NumberUtils;
17
import org.gvsig.expressionevaluator.ExpressionUtils;
17 18
import org.gvsig.fmap.dal.DALLocator;
18 19
import org.gvsig.fmap.dal.DataManager;
19 20
import org.gvsig.fmap.dal.DataStore;
......
21 22
import org.gvsig.fmap.dal.DatabaseWorkspaceManager;
22 23
import org.gvsig.fmap.dal.exception.ValidateDataParametersException;
23 24
import org.gvsig.fmap.dal.feature.EditableFeature;
25
import org.gvsig.fmap.dal.feature.EditableFeatureAttributeDescriptor;
24 26
import org.gvsig.fmap.dal.feature.EditableFeatureType;
25 27
import org.gvsig.fmap.dal.feature.Feature;
28
import org.gvsig.fmap.dal.feature.FeatureQuery;
26 29
import org.gvsig.fmap.dal.feature.FeatureStore;
27 30
import org.gvsig.fmap.dal.feature.NewFeatureStoreParameters;
28 31
import org.gvsig.fmap.dal.feature.impl.DefaultFeature;
29 32
import org.gvsig.fmap.dal.feature.spi.FeatureProvider;
33
import org.gvsig.fmap.dal.impl.expressionevaluator.DefaultFeatureAttributeEmulatorExpression;
30 34
import org.gvsig.fmap.dal.store.jdbc.JDBCServerExplorerParameters;
31 35
import org.gvsig.fmap.dal.store.jdbc.JDBCStoreParameters;
32 36
import org.gvsig.tools.resourcesstorage.ResourcesStorage;
......
137 141
        public boolean normaliceSpaces = false;
138 142
        public boolean stripStart = false;
139 143
        public boolean removeNL = false;
144
        public boolean replace_nl_by_space = false;
145
        public boolean trim_end = false;
146
        
140 147

  
141 148
        public String startLineComment = "-- ";
142 149
        
......
176 183
            boolean localNormaliceSpaces = false;
177 184
            boolean localStripStart = false;
178 185
            boolean localRemoveNL = false;
186
            boolean local_replace_nl_by_space = false;
187
            boolean local_trim_end = false;
179 188
            String name = f.getName();
180 189

  
181 190
            List<String> lines = FileUtils.readLines(f);
......
197 206
                        } else if (line.toLowerCase().startsWith(startLineComment + "remove-nl")) {
198 207
                            CommandLine cmd = new CommandLine(line, startLineComment);
199 208
                            removeNL = cmd.isTrue(1, true);
209
                        } else if (line.toLowerCase().startsWith(startLineComment + "replace-nl-by-space")) {
210
                            CommandLine cmd = new CommandLine(line, startLineComment);
211
                            replace_nl_by_space = cmd.isTrue(1, true);
212
                        } else if (line.toLowerCase().startsWith(startLineComment + "trim-end")) {
213
                            CommandLine cmd = new CommandLine(line, startLineComment);
214
                            trim_end = cmd.isTrue(1, true);
200 215
                        } else if (line.toLowerCase().startsWith(startLineComment + "begin ")) {
201 216
                            CommandLine cmd = new CommandLine(line, startLineComment);
202 217
                            currentItem = cmd.get(1);
......
205 220
                            localNormaliceSpaces = normaliceSpaces;
206 221
                            localStripStart = stripStart;
207 222
                            localRemoveNL = removeNL;
223
                            local_replace_nl_by_space = replace_nl_by_space;
224
                            local_trim_end = trim_end;
208 225
                        } else if (line.toLowerCase().startsWith(startLineComment + "rem ")) {
209 226
                            // do nothing skip comment
210 227
                        } else if (!StringUtils.isBlank(line)) {
......
221 238
                        } else if (line.toLowerCase().startsWith(startLineComment + "remove-nl")) {
222 239
                            CommandLine cmd = new CommandLine(line, startLineComment);
223 240
                            localRemoveNL = cmd.isTrue(1, true);
241
                        } else if (line.toLowerCase().startsWith(startLineComment + "replace-nl-by-space")) {
242
                            CommandLine cmd = new CommandLine(line, startLineComment);
243
                            local_replace_nl_by_space = cmd.isTrue(1, true);
244
                        } else if (line.toLowerCase().startsWith(startLineComment + "trim-end")) {
245
                            CommandLine cmd = new CommandLine(line, startLineComment);
246
                            local_trim_end = cmd.isTrue(1, true);
224 247
                        } else if (line.toLowerCase().startsWith(startLineComment + "end ")) {
225 248
                            CommandLine cmd = new CommandLine(line, startLineComment);
226 249
                            if (!StringUtils.equals(currentItem, cmd.get(1)) )  {
......
233 256
                            if (localNormaliceSpaces) {
234 257
                                s = StringUtils.normalizeSpace(s);
235 258
                            }
259
                            if( local_trim_end ) {
260
                                s = StringUtils.stripEnd(s, " ");
261
                            }
236 262
                            
237 263
                            List<String> value = expecteds.get(currentItem);
238 264
                            if( value == null ) {
......
248 274
                            if (localStripStart) {
249 275
                                line = StringUtils.stripStart(line, null);
250 276
                            }
277
                            if( local_replace_nl_by_space ) {
278
                                line = line.replace('\n', ' ');
279
                            }
251 280
                            if (localRemoveNL) {
252 281
                                line = StringUtils.remove(line, "\n");
253 282
                                line = StringUtils.remove(line, "\r");
......
478 507
    public abstract String getProviderName();
479 508
    
480 509
    public abstract JDBCServerExplorerParameters getServerExplorerParameters(String dbname) throws Exception;
510

  
511
    public void runSQLToCheckSyntax(String testName, FeatureStore datacsv, String testTableName, String sql) throws Exception {
512
        JDBCServerExplorer explorer = this.openServerExplorer(testName);
513

  
514
        this.info_jdbc(explorer);
515
        this.drop_tables(explorer, testTableName);
516

  
517
        this.create_table_from(explorer, testTableName, datacsv);
518
        this.insert_into_from(explorer, testTableName, datacsv, FeatureStore.MODE_APPEND);
519

  
520
        explorer.execute(sql);
521
    }
522
    
523
    public void output_results(String testName, String sqlresult, String sqlexpected) {
524
        System.out.println("###### "+testName+"()");
525
        System.out.println("###### SQL:" + sqlresult+";");
526
        System.out.println("###### EXP:" + sqlexpected+";");
527
    }
528

  
529
    public EditableFeatureAttributeDescriptor addExtraColumn(EditableFeatureType eFeatureType, FeatureQuery query, String name, int type, String exp) {
530
        EditableFeatureAttributeDescriptor extraColumn = query.getExtraColumn().add(name, type);
531
        extraColumn.setFeatureAttributeEmulator(new DefaultFeatureAttributeEmulatorExpression(eFeatureType, ExpressionUtils.createExpression(exp)));
532
        return extraColumn;
533
    }
534

  
535

  
481 536
}

Also available in: Unified diff