PageRenderTime 35ms CodeModel.GetById 18ms app.highlight 12ms RepoModel.GetById 1ms app.codeStats 0ms

/src/test/java/nl/bitbrains/nebu/deployer/policies/TestLocalityPolicyFactory.java

https://github.com/deltaforge/nebu-core
Java | 79 lines | 60 code | 15 blank | 4 comment | 0 complexity | 5201ce5ad89c91f8ebd5ae7def3a8f02 MD5 | raw file
 1package nl.bitbrains.nebu.deployer.policies;
 2
 3import java.text.ParseException;
 4
 5import nl.bitbrains.nebu.deployer.policies.LocalityPolicy;
 6import nl.bitbrains.nebu.deployer.policies.LocalityPolicyFactory;
 7
 8import org.jdom2.Element;
 9import org.junit.Assert;
10import org.junit.Before;
11import org.junit.Test;
12import org.mockito.Mockito;
13
14/**
15 * @author Jesse Donkervliet, Tim Hegeman, and Stefan Hugtenburg
16 * 
17 */
18public class TestLocalityPolicyFactory {
19
20    private LocalityPolicyFactory factory;
21
22    @Before
23    public void setUp() {
24        this.factory = new LocalityPolicyFactory();
25    }
26
27    @Test
28    public void testGetInstance() {
29        Assert.assertNotNull(this.factory.newInstance());
30    }
31
32    @Test
33    public void testFromXMLNoSettingContent() throws ParseException {
34        final Element xml = Mockito.mock(Element.class);
35        final LocalityPolicy policy = this.factory.fromXML(xml);
36        Assert.assertNotNull(policy);
37        Assert.assertEquals(LocalityPolicy.DEFAULT_MAX_VMS_PER_HOST, policy.getMaxVMsPerHost());
38
39    }
40
41    @Test
42    public void testFromXMLNoSettingsXMLInteractions() throws ParseException {
43        final Element xml = Mockito.mock(Element.class);
44        this.factory.fromXML(xml);
45        Mockito.verify(xml, Mockito.times(1)).getChild(LocalityPolicyFactory.TAG_MAX_VMS_PER_HOST);
46        Mockito.verifyNoMoreInteractions(xml);
47    }
48
49    @Test
50    public void testFromXMLWithSettingsContent() throws ParseException {
51        final Element xml = Mockito.mock(Element.class);
52        final Element elem = Mockito.mock(Element.class);
53        final String string = "12";
54        Mockito.when(xml.getChild(LocalityPolicyFactory.TAG_MAX_VMS_PER_HOST)).thenReturn(elem);
55        Mockito.when(xml.getChildTextTrim(LocalityPolicyFactory.TAG_MAX_VMS_PER_HOST))
56                .thenReturn(string);
57
58        final LocalityPolicy policy = this.factory.fromXML(xml);
59        Assert.assertNotNull(policy);
60        Assert.assertEquals(Integer.parseInt(string), policy.getMaxVMsPerHost());
61    }
62
63    @Test
64    public void testFromXMLWithSettingsXMLInteractions() throws ParseException {
65        final Element xml = Mockito.mock(Element.class);
66        final Element elem = Mockito.mock(Element.class);
67        final String string = "12";
68        Mockito.when(xml.getChild(LocalityPolicyFactory.TAG_MAX_VMS_PER_HOST)).thenReturn(elem);
69        Mockito.when(xml.getChildTextTrim(LocalityPolicyFactory.TAG_MAX_VMS_PER_HOST))
70                .thenReturn(string);
71
72        final LocalityPolicy policy = this.factory.fromXML(xml);
73        Mockito.verify(xml, Mockito.times(1)).getChild(LocalityPolicyFactory.TAG_MAX_VMS_PER_HOST);
74        Mockito.verify(xml, Mockito.times(1))
75                .getChildTextTrim(LocalityPolicyFactory.TAG_MAX_VMS_PER_HOST);
76        Mockito.verifyNoMoreInteractions(xml);
77    }
78
79}