e6ecefd1288cbda03644f586dc4d8ddedb7ebb9a
[policy/apex-pdp.git] /
1 /*-
2  * ============LICENSE_START=======================================================
3  *  Copyright (C) 2018 Ericsson. All rights reserved.
4  * ================================================================================
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  * 
9  *      http://www.apache.org/licenses/LICENSE-2.0
10  * 
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  * 
17  * SPDX-License-Identifier: Apache-2.0
18  * ============LICENSE_END=========================================================
19  */
20
21 package org.onap.policy.apex.tools.model.generator;
22
23 import static org.junit.Assert.assertEquals;
24 import static org.junit.Assert.assertNull;
25
26 import org.junit.Test;
27 import org.onap.policy.apex.model.basicmodel.concepts.AxArtifactKey;
28 import org.onap.policy.apex.model.policymodel.concepts.AxPolicyModel;
29 import org.onap.policy.apex.model.policymodel.concepts.AxState;
30 import org.onap.policy.apex.testsuites.integration.common.model.SampleDomainModelFactory;
31
32 /**
33  * Test the Key Info Getter.
34  */
35 public class KeyInfoGetterTest {
36
37     @Test
38     public void testKeyInfoGetter() {
39         AxPolicyModel sampleModel = new SampleDomainModelFactory().getSamplePolicyModel("JAVASCRIPT");
40
41         KeyInfoGetter kiGetter = new KeyInfoGetter(sampleModel);
42
43         assertNull(kiGetter.getName(null));
44         assertEquals("SamplePolicyModelJAVASCRIPT", kiGetter.getName(sampleModel.getKey()));
45
46         assertNull(kiGetter.getUuid(null));
47         assertNull(kiGetter.getUuid(new AxArtifactKey()));
48         assertEquals(36, kiGetter.getUuid(sampleModel.getKey()).length());
49
50         assertNull(kiGetter.getDesc(null));
51         assertNull(kiGetter.getDesc(new AxArtifactKey()));
52         assertEquals("Generated description for concept referred to by key " + "\"SamplePolicyModelJAVASCRIPT:0.0.1\"",
53                         kiGetter.getDesc(sampleModel.getKey()));
54         
55         assertNull(kiGetter.getVersion(null));
56         assertEquals("0.0.1", kiGetter.getVersion(sampleModel.getKey()));
57         
58         AxState matchState = sampleModel.getPolicies().get("Policy0").getStateMap().get("Match");
59         
60         assertNull(kiGetter.getLName(null));
61         assertEquals("Match", kiGetter.getLName(matchState.getKey()));
62         
63         assertNull(kiGetter.getPName(null));
64         assertEquals("Policy0", kiGetter.getPName(matchState.getKey()));
65         
66         assertNull(kiGetter.getPVersion(null));
67         assertEquals("0.0.1", kiGetter.getPVersion(matchState.getKey()));
68         
69         assertNull(kiGetter.getPlName(null));
70         assertEquals("NULL", kiGetter.getPlName(matchState.getKey()));
71     }
72 }