2 * ============LICENSE_START=======================================================
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
21 package org.openecomp.sdc.be.tosca;
23 import static org.junit.Assert.assertTrue;
25 import java.util.HashMap;
26 import java.util.List;
30 import org.junit.Before;
31 import org.junit.Test;
32 import org.openecomp.sdc.be.config.ConfigurationManager;
33 import org.openecomp.sdc.be.tosca.CsarUtils.NonMetaArtifactInfo;
34 import org.openecomp.sdc.common.api.ConfigurationSource;
35 import org.openecomp.sdc.common.impl.ExternalConfiguration;
36 import org.openecomp.sdc.common.impl.FSConfigurationSource;
38 import fj.data.Either;
40 public class CsarUtilsTest {
43 ExternalConfiguration.setAppName("catalog-be");
46 String appConfigDir = "src/test/resources/config/catalog-be";
47 ConfigurationSource configurationSource = new FSConfigurationSource(ExternalConfiguration.getChangeListener(), appConfigDir);
48 ConfigurationManager configurationManager = new ConfigurationManager(configurationSource);
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() );
60 artifactPath = "Artifacts/Informational/OTHER/someArtifact.xml";
61 eitherNonMetaArtifact = CsarUtils.validateNonMetaArtifact(artifactPath, payloadData, collectedWarningMessages);
62 assertTrue(eitherNonMetaArtifact.isLeft() );
63 assertTrue(collectedWarningMessages.isEmpty() );
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() );
74 artifactPath = "Artifacts/Informational/Buga2/someArtifact.xml";
75 eitherNonMetaArtifact = CsarUtils.validateNonMetaArtifact(artifactPath, payloadData, collectedWarningMessages);
76 assertTrue(eitherNonMetaArtifact.isLeft() );
78 assertTrue(collectedWarningMessages.size() == 1 );
79 assertTrue(collectedWarningMessages.values().iterator().next().size() == 2);
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() );