2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2019 Nokia. 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
11 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
21 package org.openecomp.sdcrests.applicationconfig.rest.services;
23 import org.junit.Before;
24 import org.junit.Test;
25 import org.mockito.Mock;
26 import org.openecomp.core.utilities.applicationconfig.dao.type.ApplicationConfigEntity;
27 import org.openecomp.core.utilities.applicationconfig.type.ConfigurationData;
28 import org.openecomp.sdc.applicationconfig.ApplicationConfigManager;
29 import org.openecomp.sdcrests.applicationconfiguration.types.ApplicationConfigDto;
30 import org.openecomp.sdcrests.applicationconfiguration.types.ConfigurationDataDto;
31 import org.openecomp.sdcrests.wrappers.GenericCollectionWrapper;
32 import org.springframework.http.HttpStatus;
34 import javax.ws.rs.core.Response;
35 import java.io.ByteArrayInputStream;
36 import java.io.InputStream;
37 import java.util.ArrayList;
39 import static org.junit.Assert.assertEquals;
40 import static org.mockito.ArgumentMatchers.eq;
41 import static org.mockito.Mockito.verify;
42 import static org.mockito.Mockito.when;
43 import static org.mockito.MockitoAnnotations.openMocks;
45 public class ApplicationConfigurationImplTest {
48 private ApplicationConfigurationImpl applicationConfiguration;
51 ApplicationConfigManager applicationConfigManager;
56 applicationConfiguration = new ApplicationConfigurationImpl(applicationConfigManager);
60 public void validateInsertInToTableCallsManagerFunctionWithValidParameters() {
62 final String testNamespace = "namespace";
63 final String testKey = "key";
64 final String testValue = "testingValue";
65 final InputStream testInput = new ByteArrayInputStream(testValue.getBytes());
67 Response response = applicationConfiguration.insertToTable(testNamespace, testKey, testInput);
69 assertEquals(response.getStatus(), HttpStatus.OK.value());
70 verify(applicationConfigManager).insertIntoTable(eq(testNamespace),eq(testKey),eq(testValue));
74 public void validateGetFromTableReturnsValidObject() {
76 final String testNamespace = "namespace";
77 final String testKey = "key";
78 final ConfigurationData testValue = new ConfigurationData("testValue", 111);
80 when(applicationConfigManager.getFromTable(eq(testNamespace),eq(testKey))).thenReturn(testValue);
82 Response response = applicationConfiguration.getFromTable(testNamespace, testKey);
84 assertEquals(response.getEntity().getClass(), ConfigurationDataDto.class);
85 assertEquals(((ConfigurationDataDto)response.getEntity()).getValue(),testValue.getValue());
90 public void validateGetListOfConfigurationByNamespaceFromTableReturnsValidList() {
92 final String testNamespace = "namespace";
93 final ArrayList<ApplicationConfigEntity> testApplicationConfigEntities = new ArrayList<>();
94 final ApplicationConfigEntity testConfigEntity01 = new ApplicationConfigEntity();
95 final String testValue01 = "testValue01";
96 final ApplicationConfigEntity testConfigEntity02 = new ApplicationConfigEntity();
97 final String testValue02 = "testValue02";
98 testConfigEntity01.setValue(testValue01);
99 testConfigEntity02.setValue(testValue02);
100 testApplicationConfigEntities.add(testConfigEntity01);
101 testApplicationConfigEntities.add(testConfigEntity02);
103 when(applicationConfigManager.getListOfConfigurationByNamespace(eq(testNamespace)))
104 .thenReturn(testApplicationConfigEntities);
106 Response response = applicationConfiguration.getListOfConfigurationByNamespaceFromTable(testNamespace);
108 assertEquals(response.getEntity().getClass(), GenericCollectionWrapper.class);
110 ((GenericCollectionWrapper)response.getEntity()).getResults().size(),
111 testApplicationConfigEntities.size()
114 ((ApplicationConfigDto)response.readEntity(GenericCollectionWrapper.class).getResults().get(0)).getValue(),
115 testApplicationConfigEntities.get(0).getValue()
118 ((ApplicationConfigDto)response.readEntity(GenericCollectionWrapper.class).getResults().get(1)).getValue(),
119 testApplicationConfigEntities.get(1).getValue()