Fix NPE on service import
[sdc.git] / catalog-be / src / test / java / org / openecomp / sdc / be / impl / aaf / RoleAndPermissionEnumTest.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * SDC
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
10  *
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  *
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=========================================================
19  */
20
21 package org.openecomp.sdc.be.impl.aaf;
22
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;
33
34 import static org.assertj.core.api.Assertions.assertThat;
35 import static org.assertj.core.api.Assertions.catchThrowable;
36
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.";
42
43     @Test
44     public void getRoleReadOnly() {
45         Assert.assertEquals(configurationManager.getConfiguration().getAafNamespace() + prefix + "readonly", AafRoles.READ_ONLY.getRole());
46     }
47
48     @Test
49     public void getRoleAll() {
50         Assert.assertEquals(configurationManager.getConfiguration().getAafNamespace() + prefix + "all", AafRoles.ALL.getRole());
51     }
52
53     @Test
54     public void testGetEnumByStringWithExistingValue() {
55         Assert.assertEquals(AafPermission.getEnumByString(AafPermission.PermNames.READ_VALUE),
56                 AafPermission.READ);
57         Assert.assertEquals(AafPermission.getEnumByString(AafPermission.PermNames.WRITE_VALUE),
58                 AafPermission.WRITE);
59         Assert.assertEquals(AafPermission.getEnumByString(AafPermission.PermNames.DELETE_VALUE),
60                 AafPermission.DELETE);
61     }
62
63     @Test
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");
68     }
69
70 }