aboutsummaryrefslogtreecommitdiffstats
path: root/src/test/java/org/onap/sdc/tosca/parser/elements/queries/TopologyTemplateQueryTest.java
blob: 08d37089ca20f0cd18b817d35ff1209aefa675a6 (plain)
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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
package org.onap.sdc.tosca.parser.elements.queries;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;
import org.onap.sdc.tosca.parser.enums.SdcTypes;
import org.onap.sdc.tosca.parser.impl.SdcPropertyNames;
import org.onap.sdc.toscaparser.api.NodeTemplate;
import org.onap.sdc.toscaparser.api.elements.Metadata;

import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.when;
import static org.testng.Assert.assertFalse;

@RunWith(MockitoJUnitRunner.class)
public class TopologyTemplateQueryTest {

    @Mock
    private Metadata metadata;

    @Mock
    private NodeTemplate nodeTemplate;

    @Test(expected=IllegalArgumentException.class)
    public void objectIsNotTopologyTemplate() {
       TopologyTemplateQuery.newBuilder(SdcTypes.CP)
               .build();
    }

    @Test
    public void templateIsFoundByTypeOnly() {
        TopologyTemplateQuery topologyTemplateQuery = TopologyTemplateQuery.newBuilder(SdcTypes.SERVICE)
                .build();
        when(nodeTemplate.getMetaData()).thenReturn(metadata);
        when(metadata.getValue(SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID)).thenReturn("345");
        when(metadata.getValue(SdcPropertyNames.PROPERTY_NAME_TYPE)).thenReturn(SdcTypes.SERVICE.getValue());
        assertTrue(topologyTemplateQuery.isMatchingSearchCriteria(nodeTemplate));
    }

    @Test
    public void templateIsNotFoundWhenMetadataIsNull() {
        TopologyTemplateQuery topologyTemplateQuery = TopologyTemplateQuery.newBuilder(SdcTypes.VF)
                .build();
        when(nodeTemplate.getMetaData()).thenReturn(null);
        assertFalse(topologyTemplateQuery.isMatchingSearchCriteria(nodeTemplate));
    }

    @Test
    public void templateIsFoundIfItIsService() {
        TopologyTemplateQuery topologyTemplateQuery = TopologyTemplateQuery.newBuilder(SdcTypes.SERVICE)
                .build();
        when(nodeTemplate.getMetaData()).thenReturn(metadata);
        when(metadata.getValue(SdcPropertyNames.PROPERTY_NAME_TYPE)).thenReturn(SdcTypes.SERVICE.getValue());
        assertTrue(topologyTemplateQuery.isMatchingSearchCriteria(nodeTemplate));
    }

    @Test
    public void templateIsFoundByTypeAndCUUID() {
        TopologyTemplateQuery topologyTemplateQuery = TopologyTemplateQuery.newBuilder(SdcTypes.CVFC)
                .customizationUUID("345")
                .build();
        when(nodeTemplate.getMetaData()).thenReturn(metadata);
        when(metadata.getValue(SdcPropertyNames.PROPERTY_NAME_TYPE)).thenReturn(SdcTypes.CVFC.getValue());
        when(metadata.getValue(SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID)).thenReturn("345");
        assertTrue(topologyTemplateQuery.isMatchingSearchCriteria(nodeTemplate));
    }

    @Test
    public void templateIsNotFoundWhenTypeIsNotMatchedAndCuuidIsNotSet() {
        TopologyTemplateQuery topologyTemplateQuery = TopologyTemplateQuery.newBuilder(SdcTypes.CVFC)
                .build();
        when(nodeTemplate.getMetaData()).thenReturn(metadata);
        when(metadata.getValue(SdcPropertyNames.PROPERTY_NAME_TYPE)).thenReturn(SdcTypes.VF.getValue());
        assertFalse(topologyTemplateQuery.isMatchingSearchCriteria(nodeTemplate));
    }

    @Test
    public void templateIsFoundWhenTypeIsMatchedCuuidIsProvidedAndCuuidIsNullInMetadata() {
        TopologyTemplateQuery topologyTemplateQuery = TopologyTemplateQuery.newBuilder(SdcTypes.VF)
                .customizationUUID("2345")
                .build();
        when(nodeTemplate.getMetaData()).thenReturn(metadata);
        when(metadata.getValue(SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID)).thenReturn(null);
        when(metadata.getValue(SdcPropertyNames.PROPERTY_NAME_TYPE)).thenReturn(SdcTypes.VF.getValue());
        assertFalse(topologyTemplateQuery.isMatchingSearchCriteria(nodeTemplate));
    }

    @Test
    public void templateIsFoundWhenTypeIsMatchedAndCuuidIsNullInMetadata() {
        TopologyTemplateQuery topologyTemplateQuery = TopologyTemplateQuery.newBuilder(SdcTypes.VF)
                .build();
        when(nodeTemplate.getMetaData()).thenReturn(metadata);
        when(metadata.getValue(SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID)).thenReturn(null);
        when(metadata.getValue(SdcPropertyNames.PROPERTY_NAME_TYPE)).thenReturn(SdcTypes.VF.getValue());
        assertTrue(topologyTemplateQuery.isMatchingSearchCriteria(nodeTemplate));
    }

    @Test
    public void templateIsNotFoundWhenTypeIsMatchedAndCuuidIsSet() {
        TopologyTemplateQuery topologyTemplateQuery = TopologyTemplateQuery.newBuilder(SdcTypes.CVFC)
                .customizationUUID("345")
                .build();
        when(nodeTemplate.getMetaData()).thenReturn(metadata);
        when(metadata.getValue(SdcPropertyNames.PROPERTY_NAME_TYPE)).thenReturn(SdcTypes.CVFC.getValue());
        when(metadata.getValue(SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID)).thenReturn("345");
        assertTrue(topologyTemplateQuery.isMatchingSearchCriteria(nodeTemplate));
    }

    @Test
    public void templateIsNotFoundWhenTypeIsNotMatchedAndCuuidIsSet() {
        TopologyTemplateQuery topologyTemplateQuery = TopologyTemplateQuery.newBuilder(SdcTypes.CR)
                .customizationUUID("345")
                .build();
        when(nodeTemplate.getMetaData()).thenReturn(metadata);
        when(metadata.getValue(SdcPropertyNames.PROPERTY_NAME_TYPE)).thenReturn(SdcTypes.CVFC.getValue());
        when(metadata.getValue(SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID)).thenReturn("345");
        assertFalse(topologyTemplateQuery.isMatchingSearchCriteria(nodeTemplate));
    }


}