aboutsummaryrefslogtreecommitdiffstats
path: root/openecomp-be/backend/openecomp-sdc-vendor-license-manager/src/test/java/org/openecomp/sdc/vendorlicense/licenseartifacts/impl/VendorLicenseArtifactsServiceTest.java
blob: 778caf3756c7f350ec79e675190658a31f35c563 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
package org.openecomp.sdc.vendorlicense.licenseartifacts.impl;

import org.apache.commons.io.IOUtils;
import org.apache.commons.lang3.StringUtils;
import org.openecomp.sdc.vendorlicense.ArtifactTestUtils;
import org.openecomp.sdc.vendorlicense.dao.types.EntitlementMetric;
import org.openecomp.sdc.vendorlicense.dao.types.EntitlementPoolEntity;
import org.openecomp.sdc.vendorlicense.dao.types.LicenseKeyGroupEntity;
import org.openecomp.sdc.vendorlicense.dao.types.OperationalScope;
import org.openecomp.sdc.versioning.dao.types.Version;
import org.openecomp.core.utilities.file.FileContentHandler;
import org.testng.Assert;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;

import java.io.IOException;
import java.nio.charset.StandardCharsets;

public class VendorLicenseArtifactsServiceTest extends ArtifactTestUtils {
    private FileContentHandler licenseArtifacts;


    @Test
    public void createVNFArtifact() throws Exception {
        Version vlmVersion = vspDetails.getVlmVersion();
        licenseArtifacts = vendorLicenseArtifactsService.createLicenseArtifacts(vspDetails.getId(), vspDetails.getVendorId(), vlmVersion, vspDetails.getFeatureGroups(), USER1);
        String actual = IOUtils.toString(licenseArtifacts.getFileContent(
            org.openecomp.sdc.vendorlicense.VendorLicenseConstants.VNF_ARTIFACT_NAME_WITH_PATH), StandardCharsets.UTF_8);
//        System.out.println("createVnfArtifact = " + actual);

        Assert.assertTrue(actual.contains("type"));
        Assert.assertFalse(actual.contains(lkg13Id));
        Assert.assertTrue(actual.contains(OperationalScope.Availability_Zone.toString()));
        Assert.assertTrue(actual.contains("vf-id"));
        Assert.assertFalse(actual.contains(org.openecomp.sdc.vendorlicense.VendorLicenseConstants.VENDOR_LICENSE_MODEL_ARTIFACT_REGEX_REMOVE));
        Assert.assertFalse(actual.contains("80.0"));
        Assert.assertTrue(actual.contains("80"));

    }

    @Test
    public void createVendorLicenseArtifact() throws Exception {
        Version vlmVersion = vspDetails.getVlmVersion();

        licenseArtifacts = vendorLicenseArtifactsService.createLicenseArtifacts(vspDetails.getId(), vspDetails.getVendorId(), vlmVersion, vspDetails.getFeatureGroups(), USER1);
        String actual = IOUtils.toString(licenseArtifacts.getFileContent(
            org.openecomp.sdc.vendorlicense.VendorLicenseConstants.VENDOR_LICENSE_MODEL_ARTIFACT_NAME_WITH_PATH), StandardCharsets.UTF_8);

//        System.out.println("createVendorLicenseArtifact = " + actual);
        Assert.assertFalse(actual.contains(lkg11Id));
        Assert.assertFalse(actual.contains(ep11Id));
        Assert.assertTrue(actual.contains("type"));
        Assert.assertTrue(actual.contains(EntitlementMetric.Core.toString()));
        Assert.assertTrue(actual.contains("entitlement-pool-list"));
        Assert.assertFalse(actual.contains(org.openecomp.sdc.vendorlicense.VendorLicenseConstants.VENDOR_LICENSE_MODEL_ARTIFACT_REGEX_REMOVE));

        Assert.assertTrue(actual.contains("vendor-license-model"));
        Assert.assertFalse(actual.contains("80.0"));
        Assert.assertTrue(actual.contains("80"));
    }

    @Test
    public void vNFArtifactContainsCurrentVLMVersion() throws IOException {
        super.setVlm2FirstVersion();
        licenseArtifacts = vendorLicenseArtifactsService.createLicenseArtifacts(vsp2.getId(), vsp2.getVendorId(), vsp2.getVlmVersion(), vsp2.getFeatureGroups(), USER1);
        String actual = IOUtils.toString(licenseArtifacts.getFileContent(
            org.openecomp.sdc.vendorlicense.VendorLicenseConstants.VNF_ARTIFACT_NAME_WITH_PATH), StandardCharsets.UTF_8);

        Assert.assertTrue(actual.contains(ep21.getVersionUuId()));
    }

    @Test
    public void vnfArtifactContainsSameIdAsVLMArtifact() throws IOException {
        Version vlmVersion = vspDetails.getVlmVersion();
        licenseArtifacts = vendorLicenseArtifactsService.createLicenseArtifacts(vspDetails.getId(), vspDetails.getVendorId(), vlmVersion, vspDetails.getFeatureGroups(), USER1);
        String actualVnfArtifact = IOUtils.toString(licenseArtifacts.getFileContent(
            org.openecomp.sdc.vendorlicense.VendorLicenseConstants.VNF_ARTIFACT_NAME_WITH_PATH), StandardCharsets.UTF_8);
        String actualVendorLicenseArtifact = IOUtils.toString(licenseArtifacts.getFileContent(
            org.openecomp.sdc.vendorlicense.VendorLicenseConstants.VENDOR_LICENSE_MODEL_ARTIFACT_NAME_WITH_PATH), StandardCharsets.UTF_8);

        String firstLKGUUID = actualVnfArtifact.substring(actualVnfArtifact.indexOf("<license-key-group-uuid>") + 24, actualVnfArtifact.indexOf("<license-key-group-uuid>") + 60);
        Assert.assertTrue(actualVendorLicenseArtifact.contains(firstLKGUUID));

        String firstEPUUID = actualVnfArtifact.substring(actualVnfArtifact.indexOf("<<entitlement-pool-uuid>>") + 23, actualVnfArtifact.indexOf("<<entitlement-pool-uuid>>") + 60);
        Assert.assertTrue(actualVendorLicenseArtifact.contains(firstEPUUID));
    }


    @Test
    public void vNFArtifactContainsPreviousVLMVersionAndNotLatest() throws IOException {
        super.setVlm2SecondVersion();
        licenseArtifacts = vendorLicenseArtifactsService.createLicenseArtifacts(vsp2.getId(), vsp2.getVendorId(), vsp2.getVlmVersion(), vsp2.getFeatureGroups(), USER1);
        String actual = IOUtils.toString(licenseArtifacts.getFileContent(
            org.openecomp.sdc.vendorlicense.VendorLicenseConstants.VNF_ARTIFACT_NAME_WITH_PATH), StandardCharsets.UTF_8);

        Assert.assertTrue(actual.contains(lkg21.getVersionUuId()));
        Assert.assertTrue(actual.contains(ep21.getVersionUuId()));
        Assert.assertFalse(actual.contains(lkg22Id));
        Assert.assertFalse(actual.contains(ep22Id));


        Assert.assertTrue(actual.contains("80"));
    }


    @Test
    public void onlyAddChangedEntitiesToVendorArtifact() throws IOException {
        Version vlmVersion = vspDetails.getVlmVersion();

        EntitlementPoolEntity updatedEP = ep11;
        String updatedNameEP = "updatedNameEP";
        updatedEP.setName(updatedNameEP);
        LicenseKeyGroupEntity updatedLKG = new LicenseKeyGroupEntity();
        updatedLKG.setId(lkg11Id);
        updatedLKG.setVendorLicenseModelId(lkg11.getVendorLicenseModelId());
        String updateDescLKG = "UpdateDescLKG";
        updatedLKG.setName(lkg11.getName());
        updatedLKG.setDescription(updateDescLKG);

        createThirdFinalVersionForVLMChangeEpLKGInSome(ep11.getVendorLicenseModelId(), updatedEP, updatedLKG);
        licenseArtifacts = vendorLicenseArtifactsService.createLicenseArtifacts(vspDetails.getId(), vspDetails.getVendorId(), vlmVersion, vspDetails.getFeatureGroups(), USER1);
        String actual = IOUtils.toString(licenseArtifacts.getFileContent(
            org.openecomp.sdc.vendorlicense.VendorLicenseConstants.VENDOR_LICENSE_MODEL_ARTIFACT_NAME_WITH_PATH), StandardCharsets.UTF_8);
//        System.out.println("onlyAddChangedEntitiesToVendorArtifact = " + actual);

        int countUpdatedLKG = StringUtils.countMatches(actual, updateDescLKG);
        Assert.assertEquals(countUpdatedLKG, 1);

        int countUpdatedEp = StringUtils.countMatches(actual, updatedNameEP);
        Assert.assertEquals(countUpdatedEp, 1);

        int epOccurrences = StringUtils.countMatches(actual, "<entitlement-pool>");
        Assert.assertEquals(epOccurrences, 3);
    }

    @BeforeClass
    public void setUp() {
        super.setUp();
    }
}