2 * Copyright © 2019 iconectiv
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 package org.openecomp.core.externaltesting.impl;
19 import org.apache.commons.io.IOUtils;
20 import org.junit.Assert;
21 import org.junit.Test;
22 import org.mockito.Mock;
23 import org.mockito.MockitoAnnotations;
24 import org.openecomp.core.externaltesting.api.VtpTestExecutionRequest;
25 import org.openecomp.core.externaltesting.errors.ExternalTestingException;
26 import org.openecomp.sdc.vendorsoftwareproduct.OrchestrationTemplateCandidateManager;
27 import org.openecomp.sdc.vendorsoftwareproduct.VendorSoftwareProductManager;
28 import org.openecomp.sdc.versioning.VersioningManager;
29 import org.springframework.core.io.ByteArrayResource;
30 import org.springframework.util.LinkedMultiValueMap;
31 import org.springframework.util.MultiValueMap;
33 import java.io.FileInputStream;
36 public class CsarMetadataVariableResolverTest {
39 private VersioningManager versioningManager;
42 private VendorSoftwareProductManager vendorSoftwareProductManager;
45 private OrchestrationTemplateCandidateManager candidateManager;
48 public void testResolverResolves() throws Exception {
49 MockitoAnnotations.initMocks(this);
50 CsarMetadataVariableResolver resolver = new CsarMetadataVariableResolver(versioningManager,
51 vendorSoftwareProductManager, candidateManager);
54 VtpTestExecutionRequest doesNotResolve = new VtpTestExecutionRequest();
55 Assert.assertFalse("should not resolve empty request", resolver.resolvesVariablesForRequest(doesNotResolve));
57 doesNotResolve.setParameters(new HashMap<>());
58 Assert.assertFalse("should not resolve empty parameters", resolver.resolvesVariablesForRequest(doesNotResolve));
62 VtpTestExecutionRequest resolves = new VtpTestExecutionRequest();
63 resolves.setParameters(new HashMap<>());
64 resolves.getParameters().put(CsarMetadataVariableResolver.VSP_VERSION, "1.0");
65 resolves.getParameters().put(CsarMetadataVariableResolver.VSP_ID, "vspid");
66 resolves.getParameters().put(CsarMetadataVariableResolver.CSAR_PREFIX + "MainServiceTemplate.yaml", "");
67 Assert.assertTrue("should resolve", resolver.resolvesVariablesForRequest(resolves));
69 MultiValueMap<String,Object> fakeRequestBody = new LinkedMultiValueMap<>();
72 resolver.resolve(resolves, fakeRequestBody);
74 catch (ExternalTestingException e) {
75 // exception expected.
78 // test the metadata extraction on a know CSAR zip.
79 byte[] zip = IOUtils.toByteArray(new FileInputStream("src/test/data/csar.zip"));
80 resolver.processArchive(resolves, fakeRequestBody, zip);
81 Assert.assertTrue("body contains file", fakeRequestBody.containsKey("file"));
82 LinkedList ll = (LinkedList)fakeRequestBody.get("file");
83 Assert.assertEquals("body contains one file", 1, ll.size());
84 ByteArrayResource res = (ByteArrayResource)ll.get(0);
85 Assert.assertEquals("file should have matching name", "MainServiceTemplate.yaml", res.getFilename());