re base code
[sdc.git] / catalog-be / src / test / java / org / openecomp / sdc / be / tosca / CsarUtilsTest.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * SDC
4  * ================================================================================
5  * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6  * ================================================================================
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  * 
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  * 
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  * ============LICENSE_END=========================================================
19  */
20
21 package org.openecomp.sdc.be.tosca;
22
23 import fj.data.Either;
24 import org.junit.Before;
25 import org.junit.Test;
26 import org.openecomp.sdc.be.config.ConfigurationManager;
27 import org.openecomp.sdc.be.tosca.CsarUtils.NonMetaArtifactInfo;
28 import org.openecomp.sdc.common.api.ConfigurationSource;
29 import org.openecomp.sdc.common.impl.ExternalConfiguration;
30 import org.openecomp.sdc.common.impl.FSConfigurationSource;
31
32 import java.util.HashMap;
33 import java.util.List;
34 import java.util.Map;
35 import java.util.Set;
36
37 import static org.junit.Assert.assertEquals;
38 import static org.junit.Assert.assertTrue;
39
40 public class CsarUtilsTest {
41     @Before
42     public void setup() {
43         ExternalConfiguration.setAppName("catalog-be");
44
45         // init Configuration
46         String appConfigDir = "src/test/resources/config/catalog-be";
47         ConfigurationSource configurationSource = new FSConfigurationSource(ExternalConfiguration.getChangeListener(), appConfigDir);
48         ConfigurationManager configurationManager = new ConfigurationManager(configurationSource);
49     }
50
51     @Test
52     public void testValidateNonMetaArtifactHappyScenario(){
53         String artifactPath = "Artifacts/Deployment/YANG_XML/myYang.xml";
54         byte[] payloadData = "some payload data".getBytes();
55         Map<String, Set<List<String>>> collectedWarningMessages = new HashMap<>();
56         Either<NonMetaArtifactInfo, Boolean> eitherNonMetaArtifact = CsarUtils.validateNonMetaArtifact(artifactPath, payloadData, collectedWarningMessages);
57         assertTrue(eitherNonMetaArtifact.isLeft() );
58         assertTrue(collectedWarningMessages.isEmpty() );
59
60         artifactPath = "Artifacts/Informational/OTHER/someArtifact.xml";
61         eitherNonMetaArtifact = CsarUtils.validateNonMetaArtifact(artifactPath, payloadData, collectedWarningMessages);
62         assertTrue(eitherNonMetaArtifact.isLeft() );
63         assertTrue(collectedWarningMessages.isEmpty() );
64     }
65
66     @Test
67     public void testValidateNonMetaArtifactScenarioWithWarnnings(){
68         String artifactPath = "Artifacts/Deployment/Buga/myYang.xml";
69         byte[] payloadData = "some payload data".getBytes();
70         Map<String, Set<List<String>>> collectedWarningMessages = new HashMap<>();
71         Either<NonMetaArtifactInfo, Boolean> eitherNonMetaArtifact = CsarUtils.validateNonMetaArtifact(artifactPath, payloadData, collectedWarningMessages);
72         assertTrue(eitherNonMetaArtifact.isLeft() );
73
74         artifactPath = "Artifacts/Informational/Buga2/someArtifact.xml";
75         eitherNonMetaArtifact = CsarUtils.validateNonMetaArtifact(artifactPath, payloadData, collectedWarningMessages);
76         assertTrue(eitherNonMetaArtifact.isLeft() );
77
78         assertEquals(1, collectedWarningMessages.size());
79         assertEquals(2, collectedWarningMessages.values().iterator().next().size());
80     }
81
82     @Test
83     public void testValidateNonMetaArtifactUnhappyScenario(){
84         String artifactPath = "Artifacts/Buga/YANG_XML/myYang.xml";
85         byte[] payloadData = "some payload data".getBytes();
86         Map<String, Set<List<String>>> collectedWarningMessages = new HashMap<>();
87         Either<NonMetaArtifactInfo, Boolean> eitherNonMetaArtifact = CsarUtils.validateNonMetaArtifact(artifactPath, payloadData, collectedWarningMessages);
88         assertTrue(eitherNonMetaArtifact.isRight() );
89         assertTrue( !collectedWarningMessages.isEmpty() );
90     }
91 }