summaryrefslogtreecommitdiffstats
path: root/configgen/src/test/java/com/yahoo/config/codegen/MakeConfigTest.java
blob: 501d7778fd749d8437422acfe87d0617cf36c91b (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.config.codegen;

import static org.junit.Assert.*;

import java.io.File;
import java.io.IOException;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;

public class MakeConfigTest {

    File dest;
    
    @Before
    public void setUp() {
        dest = new File("/tmp/"+System.currentTimeMillis()+File.separator);
        dest.mkdir();
    }
    
    @After
    public void tearDown() {
        recursiveDeleteDir(dest);
    }
    
    private boolean recursiveDeleteDir(File dir) {
        if (dir.isDirectory()) {
            String[] children = dir.list();

            for (int i = 0; i < children.length; i++) {
                boolean success = recursiveDeleteDir(new File(dir, children[i]));

                if (!success) return false;
            }
        }

        // The directory is now empty so delete it
        return dir.delete();
    }
    
    @Test
    public void testProps() throws PropertyException {
        long ts = System.currentTimeMillis();
        System.setProperty("config.dumpTree", "true");
        System.setProperty("config.useFramework", "true");
        System.setProperty("config.requireNamespace", "true");
        System.setProperty("config.dest", dest.getAbsolutePath());
        System.setProperty("config.spec", "src/test/resources/allfeatures.def");
        MakeConfigProperties p = new MakeConfigProperties();
        assertEquals(p.destDir.getAbsolutePath(), dest.getAbsolutePath());
        assertTrue(p.dumpTree);
        assertTrue(p.generateFrameworkCode);
        assertEquals(p.specFiles.length, 1);
        assertEquals(p.specFiles[0].getAbsolutePath(), new File("src/test/resources/allfeatures.def").getAbsolutePath());
        
        System.setProperty("config.dumpTree", "false");
        System.setProperty("config.useFramework", "false");
        System.setProperty("config.requireNamespace", "false");
        System.setProperty("config.dest", dest.getAbsolutePath());
        System.setProperty("config.spec", "src/test/resources/allfeatures.def,src/test/resources/bar.foo.def");
        p = new MakeConfigProperties();
        assertEquals(p.destDir.getAbsolutePath(), dest.getAbsolutePath());
        assertFalse(p.dumpTree);
        assertFalse(p.generateFrameworkCode);
        assertEquals(p.specFiles.length, 2);
    }

    @Test
    public void testMake() throws IOException, InterruptedException {
        System.setProperty("config.dumpTree", "true");
        System.setProperty("config.useFramework", "true");
        System.setProperty("config.requireNamespace", "true");
        System.setProperty("config.dest", dest.getAbsolutePath());
        System.setProperty("config.spec", "src/test/resources/allfeatures.def");
        MakeConfig.main(new String[]{});
    }
    
}