summaryrefslogtreecommitdiffstats
path: root/config-model/src/test/java/com/yahoo/config/model/ConfigModelUtilsTest.java
blob: 0b9efd06db07537d51f61b6415135bfb9568a8f0 (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
// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.config.model;

import com.yahoo.config.model.application.provider.Bundle;
import org.junit.Test;

import java.io.File;
import java.util.List;

import static junit.framework.TestCase.fail;
import static org.hamcrest.core.Is.is;
import static org.junit.Assert.assertThat;

/**
 * @author lulf
 * @since 5.1
 */
public class ConfigModelUtilsTest {

    /**
     * Tests that a def file both with and without namespace in file name are handled, and that
     * def files in other directories than 'configdefinitions/' within the jar file are ignored.
     */
    @Test
    public void testDefFilesInBundle() {
        List<Bundle> bundles = Bundle.getBundles(new File("src/test/cfg/application/app1/components/"));
        assertThat(bundles.size(), is(1));
        Bundle bundle = bundles.get(0);
        assertThat(bundle.getDefEntries().size(), is(2));

        Bundle.DefEntry defEntry1 = bundle.getDefEntries().get(0);
        Bundle.DefEntry defEntry2;
        List<Bundle.DefEntry> defEntries = bundle.getDefEntries();
        if (defEntry1.defName.equals("test1")) {
            defEntry2 = defEntries.get(1);
        } else {
            defEntry1 = defEntries.get(1);
            defEntry2 = defEntries.get(0);
        }
        assertThat(defEntry1.defName, is("test1"));
        assertThat(defEntry1.defNamespace, is("config"));

        assertThat(defEntry2.defName, is("test2"));
        assertThat(defEntry2.defNamespace, is("a.b"));
    }

    /**
     * Tests that an invalid jar is identified as not being a jar file
     */
    @Test
    public void testInvalidJar() {
        try {
            Bundle.getBundles(new File("src/test/cfg/application/validation/invalidjar_app/components"));
            fail();
        } catch (IllegalArgumentException e) {
            assertThat(e.getMessage(), is("Error opening jar file 'invalid.jar'. Please check that this is a valid jar file"));
        }
    }
}