8883786d7eb88ae02bf209a96785ef57ad9fbb70
[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.assertTrue;
38
39 public class CsarUtilsTest {
40     @Before
41     public void setup() {
42         ExternalConfiguration.setAppName("catalog-be");
43
44         // init Configuration
45         String appConfigDir = "src/test/resources/config/catalog-be";
46         ConfigurationSource configurationSource = new FSConfigurationSource(ExternalConfiguration.getChangeListener(), appConfigDir);
47         ConfigurationManager configurationManager = new ConfigurationManager(configurationSource);
48     }
49
50     @Test
51     public void testValidateNonMetaArtifactHappyScenario(){
52         String artifactPath = "Artifacts/Deployment/YANG_XML/myYang.xml";
53         byte[] payloadData = "some payload data".getBytes();
54         Map<String, Set<List<String>>> collectedWarningMessages = new HashMap<>();
55         Either<NonMetaArtifactInfo, Boolean> eitherNonMetaArtifact = CsarUtils.validateNonMetaArtifact(artifactPath, payloadData, collectedWarningMessages);
56         assertTrue(eitherNonMetaArtifact.isLeft() );
57         assertTrue(collectedWarningMessages.isEmpty() );
58
59         artifactPath = "Artifacts/Informational/OTHER/someArtifact.xml";
60         eitherNonMetaArtifact = CsarUtils.validateNonMetaArtifact(artifactPath, payloadData, collectedWarningMessages);
61         assertTrue(eitherNonMetaArtifact.isLeft() );
62         assertTrue(collectedWarningMessages.isEmpty() );
63     }
64
65     @Test
66     public void testValidateNonMetaArtifactScenarioWithWarnnings(){
67         String artifactPath = "Artifacts/Deployment/Buga/myYang.xml";
68         byte[] payloadData = "some payload data".getBytes();
69         Map<String, Set<List<String>>> collectedWarningMessages = new HashMap<>();
70         Either<NonMetaArtifactInfo, Boolean> eitherNonMetaArtifact = CsarUtils.validateNonMetaArtifact(artifactPath, payloadData, collectedWarningMessages);
71         assertTrue(eitherNonMetaArtifact.isLeft() );
72
73         artifactPath = "Artifacts/Informational/Buga2/someArtifact.xml";
74         eitherNonMetaArtifact = CsarUtils.validateNonMetaArtifact(artifactPath, payloadData, collectedWarningMessages);
75         assertTrue(eitherNonMetaArtifact.isLeft() );
76
77         assertTrue(collectedWarningMessages.size() == 1 );
78         assertTrue(collectedWarningMessages.values().iterator().next().size() == 2);
79     }
80
81     @Test
82     public void testValidateNonMetaArtifactUnhappyScenario(){
83         String artifactPath = "Artifacts/Buga/YANG_XML/myYang.xml";
84         byte[] payloadData = "some payload data".getBytes();
85         Map<String, Set<List<String>>> collectedWarningMessages = new HashMap<>();
86         Either<NonMetaArtifactInfo, Boolean> eitherNonMetaArtifact = CsarUtils.validateNonMetaArtifact(artifactPath, payloadData, collectedWarningMessages);
87         assertTrue(eitherNonMetaArtifact.isRight() );
88         assertTrue( !collectedWarningMessages.isEmpty() );
89     }
90 }