~ubuntu-branches/ubuntu/raring/apgdiff/raring

« back to all changes in this revision

Viewing changes to src/test/java/cz/startnet/utils/pgdiff/PgDiffTest.java

  • Committer: Bazaar Package Importer
  • Author(s): Christoph Berg
  • Date: 2010-10-11 09:08:18 UTC
  • mfrom: (2.1.7 sid)
  • Revision ID: james.westby@ubuntu.com-20101011090818-sdw8yfemrnxo328k
Tags: 2.2.2-1
* New upstream version.
* Using changelog included in zipfile, thanks Miroslav for providing this.
* Update manpage.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/**
 
2
 * Copyright 2006 StartNet s.r.o.
 
3
 *
 
4
 * Distributed under MIT license
 
5
 */
1
6
package cz.startnet.utils.pgdiff;
2
7
 
3
8
import org.junit.Assert;
17
22
 
18
23
import java.util.Arrays;
19
24
import java.util.Collection;
 
25
import java.util.Locale;
20
26
 
21
27
/**
22
28
 * Tests for PgDiff class.
52
58
    /**
53
59
     * Creates a new PgDiffTest object.
54
60
     *
55
 
     * @param fileNameTemplate {@link #originalFileName}
 
61
     * @param fileNameTemplate {@link #fileNameTemplate}
56
62
     * @param addDefaults {@link #addDefaults}
57
63
     * @param addTransaction {@link #addTransaction}
58
64
     * @param ignoreFunctionWhitespace {@link #ignoreFunctionWhitespace}
68
74
        this.addTransaction = addTransaction;
69
75
        this.ignoreFunctionWhitespace = ignoreFunctionWhitespace;
70
76
        this.ignoreStartWith = ignoreStartWith;
 
77
        Locale.setDefault(Locale.ENGLISH);
71
78
    }
72
79
 
73
80
    /**
170
177
                    // Tests scenario where CYCLE is modified on SEQUENCE.
171
178
                    {"modify_sequence_cycle_on", false, false, false, false},
172
179
                    {"modify_sequence_cycle_off", false, false, false, false},
 
180
                    // Tests correct finding of function end.
 
181
                    {"modify_function_end_detection", false, false, false, false},
173
182
                    // Tests scenario where new FUNCTION without args is added.
174
183
                    {"add_function_noargs", false, false, false, false},
175
184
                    // Tests scenario where FUNCTION without args is dropped.
217
226
                    {"multiple_schemas", false, false, false, false},
218
227
                    // Tests scenario where --add-transaction is specified.
219
228
                    {"multiple_schemas", false, true, false, false},
 
229
                    // Tests dropping view default value
 
230
                    {"alter_view_drop_default", false, true, false, false},
 
231
                    // Tests adding view default value
 
232
                    {"alter_view_add_default", false, true, false, false},
 
233
                    // Tests changing view default value
 
234
                    {"alter_view_change_default", false, true, false, false},
220
235
                    // Tests creation of sequence with bug in MINVALUE value
221
 
                    {"add_sequence_bug2100013", false, true, false, false}
 
236
                    {"add_sequence_bug2100013", false, true, false, false},
 
237
                    // Tests view with default value
 
238
                    {"view_bug3080388", false, true, false, false}
222
239
                });
223
240
    }
224
241
 
225
242
    /**
 
243
     * Runs single test on original schema.
 
244
     *
 
245
     * @throws FileNotFoundException Thrown if expected diff file was not found.
 
246
     * @throws IOException Thrown if problem occurred while reading expected
 
247
     * diff.
 
248
     */
 
249
    @Test(timeout = 1000)
 
250
    public void runDiffSameOriginal() throws FileNotFoundException, IOException {
 
251
        final ByteArrayOutputStream diffInput = new ByteArrayOutputStream();
 
252
        final PrintWriter writer = new PrintWriter(diffInput, true);
 
253
        final PgDiffArguments arguments = new PgDiffArguments();
 
254
        PgDiff.createDiff(writer, arguments,
 
255
                PgDiffTest.class.getResourceAsStream(
 
256
                fileNameTemplate + "_original.sql"),
 
257
                PgDiffTest.class.getResourceAsStream(
 
258
                fileNameTemplate + "_original.sql"));
 
259
        writer.flush();
 
260
 
 
261
        Assert.assertEquals("File name template: " + fileNameTemplate,
 
262
                "", diffInput.toString().trim());
 
263
    }
 
264
 
 
265
    /**
 
266
     * Runs single test on new schema.
 
267
     *
 
268
     * @throws FileNotFoundException Thrown if expected diff file was not found.
 
269
     * @throws IOException Thrown if problem occurred while reading expected
 
270
     * diff.
 
271
     */
 
272
    @Test(timeout = 1000)
 
273
    public void runDiffSameNew() throws FileNotFoundException, IOException {
 
274
        final ByteArrayOutputStream diffInput = new ByteArrayOutputStream();
 
275
        final PrintWriter writer = new PrintWriter(diffInput, true);
 
276
        final PgDiffArguments arguments = new PgDiffArguments();
 
277
        PgDiff.createDiff(writer, arguments,
 
278
                PgDiffTest.class.getResourceAsStream(
 
279
                fileNameTemplate + "_new.sql"),
 
280
                PgDiffTest.class.getResourceAsStream(
 
281
                fileNameTemplate + "_new.sql"));
 
282
        writer.flush();
 
283
 
 
284
        Assert.assertEquals("File name template: " + fileNameTemplate,
 
285
                "", diffInput.toString().trim());
 
286
    }
 
287
 
 
288
    /**
226
289
     * Runs single test using class member variables.
227
290
     *
228
 
     * @throws FileNotFoundException Thrown if expected diff file was not
229
 
     *         found.
230
 
     * @throws IOException Thrown if problem occured while reading expected
231
 
     *         diff.
 
291
     * @throws FileNotFoundException Thrown if expected diff file was not found.
 
292
     * @throws IOException Thrown if problem occurred while reading expected
 
293
     * diff.
232
294
     */
233
295
    @Test(timeout = 1000)
234
296
    public void runDiff() throws FileNotFoundException, IOException {
249
311
                PgDiffTest.class.getResourceAsStream(
250
312
                fileNameTemplate + "_diff.sql")));
251
313
        final char[] part = new char[1024];
252
 
        final StringBuilder sbExpDiff = new StringBuilder();
 
314
        final StringBuilder sbExpDiff = new StringBuilder(1024);
253
315
 
254
316
        while (reader.read(part) != -1) {
255
317
            sbExpDiff.append(part);
257
319
 
258
320
        reader.close();
259
321
 
260
 
        Assert.assertEquals(
 
322
        Assert.assertEquals("File name template: " + fileNameTemplate,
261
323
                sbExpDiff.toString().trim(),
262
324
                diffInput.toString().trim());
263
325
    }