List of Input Parameters for VSP
[sdc.git] / openecomp-be / lib / openecomp-sdc-externaltesting-lib / openecomp-sdc-externaltesting-impl / src / test / java / org / openecomp / core / externaltesting / impl / CsarMetadataVariableResolverTest.java
1 /*
2  * Copyright © 2019 iconectiv
3  *
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
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16
17 package org.openecomp.core.externaltesting.impl;
18
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;
32
33 import java.io.FileInputStream;
34 import java.util.*;
35
36 public class CsarMetadataVariableResolverTest {
37
38   @Mock
39   private VersioningManager versioningManager;
40
41   @Mock
42   private VendorSoftwareProductManager vendorSoftwareProductManager;
43
44   @Mock
45   private OrchestrationTemplateCandidateManager candidateManager;
46
47   @Test
48   public void testResolverResolves() throws Exception {
49     MockitoAnnotations.initMocks(this);
50     CsarMetadataVariableResolver resolver = new CsarMetadataVariableResolver(versioningManager,
51         vendorSoftwareProductManager, candidateManager);
52     resolver.init();
53
54     VtpTestExecutionRequest doesNotResolve = new VtpTestExecutionRequest();
55     Assert.assertFalse("should not resolve empty request", resolver.resolvesVariablesForRequest(doesNotResolve));
56
57     doesNotResolve.setParameters(new HashMap<>());
58     Assert.assertFalse("should not resolve empty parameters", resolver.resolvesVariablesForRequest(doesNotResolve));
59
60
61
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));
68
69     MultiValueMap<String,Object> fakeRequestBody = new LinkedMultiValueMap<>();
70
71     try {
72       resolver.resolve(resolves, fakeRequestBody);
73     }
74     catch (ExternalTestingException e) {
75       // exception expected.
76     }
77
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());
86
87   }
88 }