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.Assert;
31 import org.junit.Before;
32 import org.junit.Test;
33 import org.openecomp.sdc.be.config.ConfigurationManager;
34 import org.openecomp.sdc.be.model.ArtifactDefinition;
35 import org.openecomp.sdc.be.model.Component;
36 import org.openecomp.sdc.be.model.Resource;
37 import org.openecomp.sdc.be.tosca.CsarUtils.NonMetaArtifactInfo;
38 import org.openecomp.sdc.common.api.ConfigurationSource;
39 import org.openecomp.sdc.common.impl.ExternalConfiguration;
40 import org.openecomp.sdc.common.impl.FSConfigurationSource;
41 import org.openecomp.sdc.exception.ResponseFormat;
43 import fj.data.Either;
45 public class CsarUtilsTest {
48 ExternalConfiguration.setAppName("catalog-be");
51 String appConfigDir = "src/test/resources/config/catalog-be";
52 ConfigurationSource configurationSource = new FSConfigurationSource(ExternalConfiguration.getChangeListener(),
54 ConfigurationManager configurationManager = new ConfigurationManager(configurationSource);
58 public void testValidateNonMetaArtifactHappyScenario() {
59 String artifactPath = "Artifacts/Deployment/YANG_XML/myYang.xml";
60 byte[] payloadData = "some payload data".getBytes();
61 Map<String, Set<List<String>>> collectedWarningMessages = new HashMap<>();
62 Either<NonMetaArtifactInfo, Boolean> eitherNonMetaArtifact = CsarUtils.validateNonMetaArtifact(artifactPath,
63 payloadData, collectedWarningMessages);
64 assertTrue(eitherNonMetaArtifact.isLeft());
65 assertTrue(collectedWarningMessages.isEmpty());
67 artifactPath = "Artifacts/Informational/OTHER/someArtifact.xml";
68 eitherNonMetaArtifact = CsarUtils.validateNonMetaArtifact(artifactPath, payloadData, collectedWarningMessages);
69 assertTrue(eitherNonMetaArtifact.isLeft());
70 assertTrue(collectedWarningMessages.isEmpty());
74 public void testValidateNonMetaArtifactScenarioWithWarnnings() {
75 String artifactPath = "Artifacts/Deployment/Buga/myYang.xml";
76 byte[] payloadData = "some payload data".getBytes();
77 Map<String, Set<List<String>>> collectedWarningMessages = new HashMap<>();
78 Either<NonMetaArtifactInfo, Boolean> eitherNonMetaArtifact = CsarUtils.validateNonMetaArtifact(artifactPath,
79 payloadData, collectedWarningMessages);
80 assertTrue(eitherNonMetaArtifact.isLeft());
82 artifactPath = "Artifacts/Informational/Buga2/someArtifact.xml";
83 eitherNonMetaArtifact = CsarUtils.validateNonMetaArtifact(artifactPath, payloadData, collectedWarningMessages);
84 assertTrue(eitherNonMetaArtifact.isLeft());
86 assertTrue(collectedWarningMessages.size() == 1);
87 assertTrue(collectedWarningMessages.values().iterator().next().size() == 2);
91 public void testValidateNonMetaArtifactUnhappyScenario() {
92 String artifactPath = "Artifacts/Buga/YANG_XML/myYang.xml";
93 byte[] payloadData = "some payload data".getBytes();
94 Map<String, Set<List<String>>> collectedWarningMessages = new HashMap<>();
95 Either<NonMetaArtifactInfo, Boolean> eitherNonMetaArtifact = CsarUtils.validateNonMetaArtifact(artifactPath,
96 payloadData, collectedWarningMessages);
97 assertTrue(eitherNonMetaArtifact.isRight());
98 assertTrue(!collectedWarningMessages.isEmpty());
101 private CsarUtils createTestSubject() {
102 return new CsarUtils();
107 public void testExtractVfcsArtifactsFromCsar() throws Exception {
108 Map<String, byte[]> csar = null;
109 Map<String, List<ArtifactDefinition>> result;
113 result = CsarUtils.extractVfcsArtifactsFromCsar(csar);
114 Assert.assertEquals(new HashMap<String, List<ArtifactDefinition>>() , result);
119 public void testHandleWarningMessages() throws Exception {
120 Map<String, Set<List<String>>> collectedWarningMessages = new HashMap<>();
123 CsarUtils.handleWarningMessages(collectedWarningMessages);
128 public void testValidateNonMetaArtifact() throws Exception {
129 String artifactPath = "";
130 byte[] payloadData = new byte[] { ' ' };
131 Map<String, Set<List<String>>> collectedWarningMessages = null;
132 Either<NonMetaArtifactInfo, Boolean> result;
135 result = CsarUtils.validateNonMetaArtifact(artifactPath, payloadData, collectedWarningMessages);