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 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;
32 import java.util.HashMap;
33 import java.util.List;
37 import static org.junit.Assert.assertTrue;
39 public class CsarUtilsTest {
42 ExternalConfiguration.setAppName("catalog-be");
45 String appConfigDir = "src/test/resources/config/catalog-be";
46 ConfigurationSource configurationSource = new FSConfigurationSource(ExternalConfiguration.getChangeListener(), appConfigDir);
47 ConfigurationManager configurationManager = new ConfigurationManager(configurationSource);
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() );
59 artifactPath = "Artifacts/Informational/OTHER/someArtifact.xml";
60 eitherNonMetaArtifact = CsarUtils.validateNonMetaArtifact(artifactPath, payloadData, collectedWarningMessages);
61 assertTrue(eitherNonMetaArtifact.isLeft() );
62 assertTrue(collectedWarningMessages.isEmpty() );
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() );
73 artifactPath = "Artifacts/Informational/Buga2/someArtifact.xml";
74 eitherNonMetaArtifact = CsarUtils.validateNonMetaArtifact(artifactPath, payloadData, collectedWarningMessages);
75 assertTrue(eitherNonMetaArtifact.isLeft() );
77 assertTrue(collectedWarningMessages.size() == 1 );
78 assertTrue(collectedWarningMessages.values().iterator().next().size() == 2);
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() );