aboutsummaryrefslogtreecommitdiffstats
path: root/container-core/src/test/java/com/yahoo/osgi/provider/model/ComponentModelTest.java
blob: 5ffce493c7b93320457be3c4666211e8bbaa9b3a (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
// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.osgi.provider.model;

import com.yahoo.container.bundle.BundleInstantiationSpecification;
import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;

/**
 * @author gjoranv
 */
public class ComponentModelTest {

    @Test
    void create_from_instantiation_spec() {
        ComponentModel model = new ComponentModel(
                BundleInstantiationSpecification.fromStrings("id", "class", "bundle"));
        verifyBundleSpec(model);
    }

    @Test
    void require_exception_upon_null_instantiation_spec() throws Exception {
        assertThrows(IllegalArgumentException.class, () -> {
            ComponentModel model = new ComponentModel(null);
        });
    }

    @Test
    void create_from_instantiation_spec_and_config_id() throws Exception {
        ComponentModel model = new ComponentModel(
                BundleInstantiationSpecification.fromStrings("id", "class", "bundle"), "configId");
        verifyBundleSpec(model);
        assertEquals("configId", model.configId);
    }

    @Test
    void create_from_strings() throws Exception {
        ComponentModel model = new ComponentModel("id", "class", "bundle", "configId");
        verifyBundleSpec(model);
        assertEquals("configId", model.configId);
    }

    private void verifyBundleSpec(ComponentModel model) {
         assertEquals("id", model.getComponentId().stringValue());
         assertEquals("class", model.getClassId().stringValue());
         assertEquals("bundle", model.bundleInstantiationSpec.bundle.stringValue());
     }
}