2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 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.openecomp.sdc.be.impl.aaf;
23 import org.junit.Assert;
24 import org.junit.Test;
25 import org.openecomp.sdc.be.components.impl.aaf.AafPermission;
26 import org.openecomp.sdc.be.components.impl.aaf.AafRoles;
27 import org.openecomp.sdc.be.components.impl.exceptions.ComponentException;
28 import org.openecomp.sdc.be.config.ConfigurationManager;
29 import org.openecomp.sdc.be.dao.api.ActionStatus;
30 import org.openecomp.sdc.common.api.ConfigurationSource;
31 import org.openecomp.sdc.common.impl.ExternalConfiguration;
32 import org.openecomp.sdc.common.impl.FSConfigurationSource;
34 import static org.assertj.core.api.Assertions.assertThat;
35 import static org.assertj.core.api.Assertions.catchThrowable;
37 public class RoleAndPermissionEnumTest {
38 private static ConfigurationSource configurationSource = new FSConfigurationSource(
39 ExternalConfiguration.getChangeListener(), "src/test/resources/config/catalog-be");
40 private static ConfigurationManager configurationManager = new ConfigurationManager(configurationSource);
41 private final String prefix = ".app.";
44 public void getRoleReadOnly() {
45 Assert.assertEquals(configurationManager.getConfiguration().getAafNamespace() + prefix + "readonly", AafRoles.READ_ONLY.getRole());
49 public void getRoleAll() {
50 Assert.assertEquals(configurationManager.getConfiguration().getAafNamespace() + prefix + "all", AafRoles.ALL.getRole());
54 public void testGetEnumByStringWithExistingValue() {
55 Assert.assertEquals(AafPermission.getEnumByString(AafPermission.PermNames.READ_VALUE),
57 Assert.assertEquals(AafPermission.getEnumByString(AafPermission.PermNames.WRITE_VALUE),
59 Assert.assertEquals(AafPermission.getEnumByString(AafPermission.PermNames.DELETE_VALUE),
60 AafPermission.DELETE);
64 public void testGetEnumByStringNonExistingValue() {
65 ComponentException thrown = (ComponentException) catchThrowable(()-> AafPermission.getEnumByString("stam"));
66 assertThat(thrown.getActionStatus()).isEqualTo(ActionStatus.INVALID_PROPERTY);
67 assertThat(thrown.getParams()[0]).isEqualTo("stam");