2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 - 2020 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
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.onap.vid.controller;
23 import static org.hamcrest.MatcherAssert.assertThat;
24 import static org.hamcrest.Matchers.equalTo;
25 import static org.mockito.Mockito.when;
26 import static org.onap.vid.testUtils.TestUtils.setStringsInStringFields;
28 import javax.inject.Inject;
29 import org.mockito.InjectMocks;
30 import org.mockito.Mock;
31 import org.mockito.MockitoAnnotations;
32 import org.onap.portalsdk.core.domain.App;
33 import org.onap.portalsdk.core.service.DataAccessService;
34 import org.onap.portalsdk.core.util.SystemProperties;
35 import org.onap.vid.config.DataSourceConfig;
36 import org.onap.vid.properties.Features;
37 import org.springframework.test.context.ContextConfiguration;
38 import org.springframework.test.context.testng.AbstractTestNGSpringContextTests;
39 import org.testng.annotations.BeforeMethod;
40 import org.testng.annotations.Test;
41 import org.togglz.core.manager.FeatureManager;
43 @ContextConfiguration(classes = {DataSourceConfig.class, SystemProperties.class})
44 public class WebConfigTest extends AbstractTestNGSpringContextTests {
46 @Inject private DataAccessService dataAccessService;
47 @Mock FeatureManager featureManager;
48 @InjectMocks WebConfig webConfig;
51 public void initMocks() {
52 MockitoAnnotations.initMocks(this);
53 webConfig.dataAccessService = dataAccessService;
55 // set default app values
56 App defaultApp = setStringsInStringFields(new App());
58 dataAccessService.saveDomainObject(defaultApp, null);
61 when(featureManager.isActive(Features.FLAG_GUILIN_CONFIG_PORTAL_APP_PASSWORD)).thenReturn(true);
65 public void persistPortalAppPassword_givenFlagAndValue_thenValueIsPersisted() {
66 assertThat(setAndGetPortalAppPassword("fresh password"),
67 equalTo("fresh password"));
71 public void persistPortalAppPassword_givenEmptyValue_thenDbValueUnchanged() {
72 assertThat(setAndGetPortalAppPassword(""),
73 equalTo("appPassword"));
77 public void persistPortalAppPassword_givenNullValue_thenDbValueUnchanged() {
78 assertThat(setAndGetPortalAppPassword(null),
79 equalTo("appPassword"));
82 public String setAndGetPortalAppPassword(String password) {
83 webConfig.portalAppPassword = password;
85 webConfig.persistPortalAppPassword();
86 return appDomainPasswordFromDB();
89 private String appDomainPasswordFromDB() {
90 return ((App) dataAccessService.getDomainObject(App.class, 1L, null))