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