blob: a946d568704f3233cc3c7350f0e8df2ef33205f0 (
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
|
// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.component.chain.model;
import com.yahoo.component.ComponentId;
import com.yahoo.component.ComponentSpecification;
import com.yahoo.container.core.ChainsConfig;
import org.junit.Test;
import java.util.Map;
import java.util.Set;
import static com.yahoo.container.core.ChainsConfig.Components;
import static com.yahoo.container.core.ChainsConfig.Chains;
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
/**
* @author gjoranv
* @since 5.1.10
*/
public class ChainsModelBuilderTest {
@Test
public void components_are_added_to_componentModels() throws Exception {
ChainsModel model = chainsModel();
assertThat(model.allComponents().size(), is(2));
assertTrue(model.componentModels().containsKey(new ComponentId("componentA")));
}
@Test
public void components_are_added_to_chainSpecification() throws Exception {
ChainsModel model = chainsModel();
ChainSpecification chainSpec = model.chainSpecifications().get(new ComponentId("chain1")).model();
assertTrue(getComponentsByName(chainSpec.componentReferences).containsKey("componentA"));
}
@Test
public void inherited_chains_are_added_to_chainSpecification() throws Exception {
ChainsModel model = chainsModel();
ChainSpecification inheritsChain1 = model.chainSpecifications().get(new ComponentId("inheritsChain1")).model();
assertThat(model.allChainsFlattened().size(), is(2));
assertTrue(getComponentsByName(inheritsChain1.inheritance.chainSpecifications).containsKey("chain1"));
assertTrue(getComponentsByName(inheritsChain1.inheritance.excludedComponents).containsKey("componentA"));
}
private ChainsModel chainsModel() {
ChainsConfig.Builder builder = new ChainsConfig.Builder()
.components(new Components.Builder()
.id("componentA"))
.components(new Components.Builder()
.id("componentB"))
.chains(new Chains.Builder()
.id("chain1")
.components("componentA")
.components("componentB"))
.chains(new Chains.Builder()
.id("inheritsChain1")
.inherits("chain1")
.excludes("componentA"));
ChainsConfig config = new ChainsConfig(builder);
ChainsModel model = ChainsModelBuilder.buildFromConfig(config);
model.validate();
return model;
}
private static Map<String, ComponentSpecification>
getComponentsByName(Set<ComponentSpecification> componentSpecifications) {
return ChainSpecification.componentsByName(componentSpecifications);
}
}
|