summaryrefslogtreecommitdiffstats
path: root/openecomp-be/backend/openecomp-sdc-vendor-license-manager/src/test/java/org/openecomp/sdc/vendorlicense/VendorLicenseFacadeImplTest.java
blob: 88257bc693cf662ee011a6d002d084827d56096e (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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
/*-
 * ============LICENSE_START=======================================================
 * SDC
 * ================================================================================
 * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
 * ================================================================================
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *      http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * ============LICENSE_END=========================================================
 */

package org.openecomp.sdc.vendorlicense;

/**
 * This test just verifies Feature Group Get and List APIs.
 */
public class VendorLicenseFacadeImplTest {
    /*

    //JUnit Test Cases using Mockito
    private static final Version VERSION01 = new Version(0, 1);
    public static final String EP1 = "ep1";
    public static final String MRN = "mrn";
    public static final String VLM_ID = "VLM_ID";
    public static final String USER = "USER1";


    @Mock
    private VendorLicenseModelDao vendorLicenseModelDao;

    @Mock
    private LicenseAgreementDao licenseAgreementDao;

    @Mock
    private FeatureGroupDao featureGroupDao;

    @Mock
    private EntitlementPoolDao entitlementPoolDao;

    @Mock
    private LicenseKeyGroupDao licenseKeyGroupDao;

    @Mock
    private VersioningManager versioningManager;

    @InjectMocks
    @Spy
    private VendorLicenseFacadeImpl vendorLicenseFacadeImpl;

    @BeforeMethod
    public void setUp() throws Exception{
        MockitoAnnotations.initMocks(this);
    }

    @Test
    public void testGetFeatureGroupWhenMRNNull () {
        resetFieldModifiers();

        FeatureGroupEntity featureGroup = createFeatureGroup();

        VersionInfo info = new VersionInfo();
        info.getViewableVersions().add(VERSION01);
        info.setActiveVersion(VERSION01);

        Set<String> entitlementPoolIds;
        entitlementPoolIds = new HashSet<>();
        entitlementPoolIds.add(EP1);

        EntitlementPoolEntity ep = createEP();

        featureGroup.setEntitlementPoolIds(entitlementPoolIds);

        doReturn(info).when(vendorLicenseFacadeImpl).getVersionInfo(anyObject(),anyObject(),anyObject());
        doReturn(featureGroup).when(featureGroupDao).get(featureGroup);
        doReturn(ep).when(entitlementPoolDao).get(anyObject());
        doReturn(MRN).when(entitlementPoolDao).getManufacturerReferenceNumber(anyObject());
        FeatureGroupEntity retrieved = vendorLicenseFacadeImpl.getFeatureGroup(featureGroup, USER);
        Assert.assertEquals(MRN, retrieved.getManufacturerReferenceNumber());
    }

    @Test
    public void testListFeatureGroups () {
        resetFieldModifiers();

        FeatureGroupEntity featureGroup = createFeatureGroup();

        Collection<FeatureGroupEntity> featureGroups = new ArrayList<FeatureGroupEntity>();
        featureGroups.add(featureGroup);

        VersionInfo info = new VersionInfo();
        info.getViewableVersions().add(VERSION01);
        info.setActiveVersion(VERSION01);

        EntitlementPoolEntity ep = createEP();

        doReturn(info).when(vendorLicenseFacadeImpl).getVersionInfo(anyObject(),anyObject(),anyObject());
        doReturn(featureGroup).when(featureGroupDao).get(featureGroup);
        doReturn(ep).when(entitlementPoolDao).get(anyObject());
        doReturn(MRN).when(entitlementPoolDao).getManufacturerReferenceNumber(anyObject());
        Collection<FeatureGroupEntity> retrieved = vendorLicenseFacadeImpl.listFeatureGroups(VLM_ID,
            VERSION01, USER);
        retrieved.stream().forEach(fg -> Assert.assertEquals(MRN,fg.getManufacturerReferenceNumber()));
    }

    @Test
    public void testSubmitLAWithoutFG()
    {
        try {
            resetFieldModifiers();

            VersionInfo info = new VersionInfo();
            info.getViewableVersions().add(VERSION01);
            info.setActiveVersion(VERSION01);

            LicenseAgreementEntity licenseAgreementEntity = new LicenseAgreementEntity();
            List<LicenseAgreementEntity> licenseAgreementEntities = new ArrayList<LicenseAgreementEntity>(){{
                add(licenseAgreementEntity);
            }};

            doReturn(info).when(vendorLicenseFacadeImpl).getVersionInfo(anyObject(),anyObject(),anyObject());
            doReturn(licenseAgreementEntities).when(licenseAgreementDao).list(anyObject());

            vendorLicenseFacadeImpl.submit(VLM_ID, USER);
            Assert.fail();
        } catch (CoreException exception) {
            org.testng.Assert.assertEquals(exception.code().message(), SUBMIT_UNCOMPLETED_VLM_MSG_LA_MISSING_FG.getErrorMessage());
        }
    }

    @Test
    public void testSubmitLAWithFGWithoutEP()
    {
        try {
            resetFieldModifiers();

            VersionInfo info = new VersionInfo();
            info.getViewableVersions().add(VERSION01);
            info.setActiveVersion(VERSION01);

            LicenseAgreementEntity licenseAgreementEntity = new LicenseAgreementEntity();
            FeatureGroupEntity featureGroupEntity = new FeatureGroupEntity();
            licenseAgreementEntity.setFeatureGroupIds(new HashSet<String>(){{
                add("54654654asdas5");
            }});
            List<LicenseAgreementEntity> licenseAgreementEntities = new ArrayList<LicenseAgreementEntity>(){{
                add(licenseAgreementEntity);
            }};

            doReturn(info).when(vendorLicenseFacadeImpl).getVersionInfo(anyObject(),anyObject(),anyObject());
            doReturn(licenseAgreementEntities).when(licenseAgreementDao).list(anyObject());
            doReturn(featureGroupEntity).when(featureGroupDao).get(anyObject());

            vendorLicenseFacadeImpl.submit(VLM_ID, USER);

            Assert.fail();
        } catch (CoreException exception) {
            org.testng.Assert.assertEquals(exception.code().message(), SUBMIT_UNCOMPLETED_VLM_MSG_FG_MISSING_EP.getErrorMessage());
        }
    }

    private void resetFieldModifiers() {
        try {
            Field fgField = VendorLicenseFacadeImpl.class.getDeclaredField("featureGroupDao");
            fgField.setAccessible(true);
            Field modifiersField = Field.class.getDeclaredField("modifiers");
            modifiersField.setAccessible(true);
            modifiersField.setInt(fgField, fgField.getModifiers() & ~Modifier.FINAL);
            fgField.set(null, featureGroupDao);

            Field epField = VendorLicenseFacadeImpl.class.getDeclaredField("entitlementPoolDao");
            epField.setAccessible(true);
            modifiersField = Field.class.getDeclaredField("modifiers");
            modifiersField.setAccessible(true);
            modifiersField.setInt(epField, epField.getModifiers() & ~Modifier.FINAL);
            epField.set(null, entitlementPoolDao);

            Field laField = VendorLicenseFacadeImpl.class.getDeclaredField("licenseAgreementDao");
            laField.setAccessible(true);
            modifiersField = Field.class.getDeclaredField("modifiers");
            modifiersField.setAccessible(true);
            modifiersField.setInt(laField, laField.getModifiers() & ~Modifier.FINAL);
            laField.set(null, licenseAgreementDao);
        } catch(NoSuchFieldException | IllegalAccessException e)
        {
            org.testng.Assert.fail();
        }
    }

    private FeatureGroupEntity createFeatureGroup() {
        FeatureGroupEntity featureGroup = new FeatureGroupEntity(VLM_ID, VERSION01, USER);
        featureGroup.setManufacturerReferenceNumber(null);
        VersionInfo info = new VersionInfo();
        info.getViewableVersions().add(VERSION01);
        info.setActiveVersion(VERSION01);

        Set<String> entitlementPoolIds;
        entitlementPoolIds = new HashSet<>();
        entitlementPoolIds.add(EP1);

        featureGroup.setEntitlementPoolIds(entitlementPoolIds);
        return featureGroup;
    }

    private EntitlementPoolEntity createEP() {
        EntitlementPoolEntity ep = new EntitlementPoolEntity(VLM_ID,VERSION01, EP1);
        ep.setManufacturerReferenceNumber(MRN);
        return ep;
    }
*/
}