Add collaboration feature
[sdc.git] / openecomp-be / backend / openecomp-sdc-vendor-license-manager / src / test / java / org / openecomp / sdc / vendorlicense / licenseartifacts / impl / VendorLicenseArtifactsServiceTest.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * SDC
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
10  * 
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  * 
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=========================================================
19  */
20
21 package org.openecomp.sdc.vendorlicense.licenseartifacts.impl;
22
23 import org.openecomp.core.utilities.file.FileContentHandler;
24 import org.openecomp.sdc.vendorlicense.ArtifactTestUtils;
25
26
27 public class VendorLicenseArtifactsServiceTest extends ArtifactTestUtils {
28   private FileContentHandler licenseArtifacts;
29 /*
30
31
32   @Test
33   public void createVNFArtifact() throws Exception {
34     Version vlmVersion = vspDetails.getVlmVersion();
35     licenseArtifacts = vendorLicenseArtifactsService
36         .createLicenseArtifacts(vspDetails.getId(), vspDetails.getVendorId(), vlmVersion,
37             vspDetails.getFeatureGroups(), USER1);
38     String actual = IOUtils.toString(
39         licenseArtifacts.getFileContent(VendorLicenseConstants.VNF_ARTIFACT_NAME_WITH_PATH),
40         StandardCharsets.UTF_8);
41         System.out.println("createVNFArtifact = " + actual);
42
43     Assert.assertTrue(actual.contains("type"));
44     Assert.assertFalse(actual.contains(lkg13Id));
45     Assert.assertTrue(actual.contains(OperationalScope.Availability_Zone.toString()));
46     Assert.assertTrue(actual.contains("vf-id"));
47     Assert.assertFalse(
48         actual.contains(VendorLicenseConstants.VENDOR_LICENSE_MODEL_ARTIFACT_REGEX_REMOVE));
49     Assert.assertFalse(actual.contains("80.0"));
50     Assert.assertTrue(actual.contains("80"));
51     Assert.assertFalse(actual.contains("versionForArtifact"));
52   }
53
54   @Test
55   public void createVendorLicenseArtifact() throws Exception {
56     Version vlmVersion = vspDetails.getVlmVersion();
57
58     licenseArtifacts = vendorLicenseArtifactsService
59         .createLicenseArtifacts(vspDetails.getId(), vspDetails.getVendorId(), vlmVersion,
60             vspDetails.getFeatureGroups(), USER1);
61     String actual = IOUtils.toString(licenseArtifacts
62             .getFileContent(VendorLicenseConstants.VENDOR_LICENSE_MODEL_ARTIFACT_NAME_WITH_PATH),
63         StandardCharsets.UTF_8);
64
65      //System.out.println("createVendorLicenseArtifact = " + actual);
66     Assert.assertTrue(actual.contains(lkg11Id));
67     Assert.assertTrue(actual.contains(ep11Id));
68     Assert.assertTrue(actual.contains("type"));
69     Assert.assertTrue(actual.contains(EntitlementMetric.Core.toString()));
70     Assert.assertTrue(actual.contains("entitlement-pool-list"));
71     Assert.assertFalse(
72         actual.contains(VendorLicenseConstants.VENDOR_LICENSE_MODEL_ARTIFACT_REGEX_REMOVE));
73
74     Assert.assertTrue(actual.contains("vendor-license-model"));
75     Assert.assertFalse(actual.contains("80.0"));
76     Assert.assertTrue(actual.contains("80"));
77   }
78
79   @Test
80   public void vNFArtifactContainsCurrentVLMVersion() throws IOException {
81     super.setVlm2FirstVersion();
82     licenseArtifacts = vendorLicenseArtifactsService
83         .createLicenseArtifacts(vsp2.getId(), vsp2.getVendorId(), vsp2.getVlmVersion(),
84             vsp2.getFeatureGroups(), USER1);
85     String actual = IOUtils.toString(
86         licenseArtifacts.getFileContent(VendorLicenseConstants.VNF_ARTIFACT_NAME_WITH_PATH),
87         StandardCharsets.UTF_8);
88
89 //        Assert.assertTrue(actual.contains(lkg21Id));
90     Assert.assertTrue(actual.contains(ep21.getVersionUuId()));
91   }
92
93   @Test
94   public void vnfArtifactContainsSameIdAsVLMArtifact() throws IOException {
95     Version vlmVersion = vspDetails.getVlmVersion();
96     licenseArtifacts = vendorLicenseArtifactsService
97         .createLicenseArtifacts(vspDetails.getId(), vspDetails.getVendorId(), vlmVersion,
98             vspDetails.getFeatureGroups(), USER1);
99     String actualVnfArtifact = IOUtils.toString(
100         licenseArtifacts.getFileContent(VendorLicenseConstants.VNF_ARTIFACT_NAME_WITH_PATH),
101         StandardCharsets.UTF_8);
102     String actualVendorLicenseArtifact = IOUtils.toString(licenseArtifacts
103             .getFileContent(VendorLicenseConstants.VENDOR_LICENSE_MODEL_ARTIFACT_NAME_WITH_PATH),
104         StandardCharsets.UTF_8);
105
106     String firstLKGUUID = actualVnfArtifact
107         .substring(actualVnfArtifact.indexOf("<license-key-group-uuid>") + 24,
108             actualVnfArtifact.indexOf("<license-key-group-uuid>") + 60);
109     Assert.assertTrue(actualVendorLicenseArtifact.contains(firstLKGUUID));
110
111     String firstEPUUID = actualVnfArtifact
112         .substring(actualVnfArtifact.indexOf("<<entitlement-pool-uuid>>") + 23,
113             actualVnfArtifact.indexOf("<<entitlement-pool-uuid>>") + 60);
114     Assert.assertTrue(actualVendorLicenseArtifact.contains(firstEPUUID));
115   }
116
117
118   //@Test
119   public void vNFArtifactContainsPreviousVLMVersionAndNotLatest() throws IOException {
120     super.setVlm2SecondVersion();
121     licenseArtifacts = vendorLicenseArtifactsService
122         .createLicenseArtifacts(vsp2.getId(), vsp2.getVendorId(), vsp2.getVlmVersion(),
123             vsp2.getFeatureGroups(), USER1);
124     String actual = IOUtils.toString(
125         licenseArtifacts.getFileContent(VendorLicenseConstants.VNF_ARTIFACT_NAME_WITH_PATH),
126         StandardCharsets.UTF_8);
127
128     Assert.assertTrue(actual.contains(lkg21.getVersionUuId()));
129     Assert.assertTrue(actual.contains(ep21.getVersionUuId()));
130     Assert.assertFalse(actual.contains(lkg22Id));
131     Assert.assertFalse(actual.contains(ep22Id));
132
133
134     Assert.assertTrue(actual.contains("80"));
135   }
136
137
138   @Test
139   public void vlmVersionTwoThenUpdatingLKGAndEpInThird() throws IOException {
140     Version vlmVersion = vspDetails.getVlmVersion();
141
142     EntitlementPoolEntity updatedEP = ep11;
143     String updatedNameEP = "updatedNameEP";
144     updatedEP.setName(updatedNameEP);
145     LicenseKeyGroupEntity updatedLKG = new LicenseKeyGroupEntity();
146     updatedLKG.setId(lkg11Id);
147     updatedLKG.setVendorLicenseModelId(lkg11.getVendorLicenseModelId());
148     String updateDescLKG = "UpdateDescLKG";
149     updatedLKG.setName(lkg11.getName());
150     updatedLKG.setDescription(updateDescLKG);
151
152     createThirdFinalVersionForVLMChangeEpLKGInSome(ep11.getVendorLicenseModelId(), updatedEP,
153         updatedLKG);
154     licenseArtifacts = vendorLicenseArtifactsService
155         .createLicenseArtifacts(vspDetails.getId(), vspDetails.getVendorId(), vlmVersion,
156             vspDetails.getFeatureGroups(), USER1);
157     String actual = IOUtils.toString(licenseArtifacts
158             .getFileContent(VendorLicenseConstants.VENDOR_LICENSE_MODEL_ARTIFACT_NAME_WITH_PATH),
159         StandardCharsets.UTF_8);
160     System.out.println("onlyAddChangedEntitiesToVendorArtifact = " + actual);
161
162     int countUpdatedLKG = StringUtils.countMatches(actual, updateDescLKG);
163     Assert.assertEquals(countUpdatedLKG, 1);
164
165     int countUpdatedEp = StringUtils.countMatches(actual, updatedNameEP);
166     Assert.assertEquals(countUpdatedEp, 1);
167
168     int epOccurrences = StringUtils.countMatches(actual, "<entitlement-pool>");
169     Assert.assertEquals(epOccurrences, 3);
170   }
171
172
173   @Test(invocationCount = 5)
174   public void vlmVersionOneThenAddEp_bug2629() throws IOException {
175     createAndSetupVlm3();
176     addEpToVLM(vlm3Id);
177     createVspWithSpecifiedVlmVersion(vlm3Id,new Version(2,0),featureGroupsforVlm3,
178         licenseAgreementVlm3.getId());
179
180     Version vlmVersion = vspDetailsVsp3.getVlmVersion();
181
182     licenseArtifacts = vendorLicenseArtifactsService
183         .createLicenseArtifacts(vspDetailsVsp3.getId(), vspDetailsVsp3.getVendorId(),
184             vlmVersion,
185             vspDetailsVsp3.getFeatureGroups(), USER1);
186     String actual = IOUtils.toString(licenseArtifacts
187             .getFileContent(VendorLicenseConstants.VENDOR_LICENSE_MODEL_ARTIFACT_NAME_WITH_PATH),
188         StandardCharsets.UTF_8);
189     System.out.println("vlmVersionOneThenAddEp_bug2629 = " + actual);
190
191     int countVersion2appearances = StringUtils.countMatches(actual, "<version>2.0</version>");
192     int countVersion1appearances = StringUtils.countMatches(actual, "<version>1.0</version>");
193     Assert.assertEquals(countVersion2appearances, 1);
194     Assert.assertEquals(countVersion1appearances, 2);
195   }
196
197
198   @BeforeClass
199   public void setUp() {
200     super.setUp();
201   }
202
203 */
204
205 }