Remove try/catch blocks with assertj - apex-pdp
[policy/apex-pdp.git] / model / basic-model / src / test / java / org / onap / policy / apex / model / basicmodel / service / ModelServiceTest.java
1 /*-
2  * ============LICENSE_START=======================================================
3  *  Copyright (C) 2016-2018 Ericsson. All rights reserved.
4  *  Modifications Copyright (C) 2020 Nordix Foundation
5  * ================================================================================
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  *      http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  *
18  * SPDX-License-Identifier: Apache-2.0
19  * ============LICENSE_END=========================================================
20  */
21
22 package org.onap.policy.apex.model.basicmodel.service;
23
24 import static org.assertj.core.api.Assertions.assertThatThrownBy;
25 import static org.junit.Assert.assertFalse;
26 import static org.junit.Assert.assertNotNull;
27 import static org.junit.Assert.assertTrue;
28
29 import org.junit.Test;
30 import org.onap.policy.apex.model.basicmodel.concepts.AxKeyInformation;
31 import org.onap.policy.apex.model.basicmodel.handling.DummyApexBasicModelCreator;
32
33 public class ModelServiceTest {
34
35     @Test
36     public void testModelService() {
37         ModelService.clear();
38
39         assertFalse(ModelService.existsModel(AxKeyInformation.class));
40         assertThatThrownBy(() -> ModelService.getModel(AxKeyInformation.class))
41             .hasMessage("Model for org.onap.policy.apex.model.basicmodel.concepts.AxKeyInformation "
42                             + "not found in model service");
43         ModelService.registerModel(AxKeyInformation.class,
44                         new DummyApexBasicModelCreator().getModel().getKeyInformation());
45         assertTrue(ModelService.existsModel(AxKeyInformation.class));
46         assertNotNull(ModelService.getModel(AxKeyInformation.class));
47
48         ModelService.deregisterModel(AxKeyInformation.class);
49
50         assertFalse(ModelService.existsModel(AxKeyInformation.class));
51         assertThatThrownBy(() -> ModelService.getModel(AxKeyInformation.class))
52             .hasMessage("Model for org.onap.policy.apex.model.basicmodel.concepts.AxKeyInformation "
53                             + "not found in model service");
54         ModelService.registerModel(AxKeyInformation.class,
55                         new DummyApexBasicModelCreator().getModel().getKeyInformation());
56         assertTrue(ModelService.existsModel(AxKeyInformation.class));
57         assertNotNull(ModelService.getModel(AxKeyInformation.class));
58
59         ModelService.clear();
60         assertFalse(ModelService.existsModel(AxKeyInformation.class));
61         assertThatThrownBy(() -> ModelService.getModel(AxKeyInformation.class))
62             .hasMessage("Model for org.onap.policy.apex.model.basicmodel.concepts.AxKeyInformation "
63                             + "not found in model service");
64     }
65 }