2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2019 Nordix Foundation.
4 * ================================================================================
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
17 * SPDX-License-Identifier: Apache-2.0
18 * ============LICENSE_END=========================================================
21 package org.onap.policy.models.base;
23 import static org.junit.Assert.assertEquals;
24 import static org.junit.Assert.assertFalse;
25 import static org.junit.Assert.assertNotNull;
26 import static org.junit.Assert.assertTrue;
27 import static org.junit.Assert.fail;
29 import org.junit.Test;
30 import org.onap.policy.models.base.testconcepts.DummyPfModel;
32 public class ModelServiceTest {
35 public void testModelService() {
36 PfModelService.clear();
38 assertFalse(PfModelService.existsModel("NonExistantName"));
40 PfModelService.getModel("NonExistantName");
41 } catch (final Exception e) {
42 assertEquals("Model for name NonExistantName not found in model service", e.getMessage());
45 PfModelService.registerModel("ModelName", new DummyPfModel());
46 assertTrue(PfModelService.existsModel("ModelName"));
47 assertNotNull(PfModelService.getModel("ModelName"));
49 PfModelService.deregisterModel("ModelName");
51 assertFalse(PfModelService.existsModel("ModelName"));
53 PfModelService.getModel("ModelName");
54 } catch (final Exception e) {
55 assertEquals("Model for name ModelName not found in model service", e.getMessage());
58 PfModelService.registerModel("ModelName", new DummyPfModel());
59 assertTrue(PfModelService.existsModel("ModelName"));
60 assertNotNull(PfModelService.getModel("ModelName"));
62 PfModelService.clear();
63 assertFalse(PfModelService.existsModel("ModelName"));
65 PfModelService.getModel("ModelName");
66 } catch (final Exception e) {
67 assertEquals("Model for name ModelName not found in model service", e.getMessage());
71 PfModelService.registerModel(null, null);
72 fail("test should throw an exception");
73 } catch (Exception exc) {
74 assertEquals("modelKey is marked @NonNull but is null", exc.getMessage());
78 PfModelService.registerModel("nullModelName", null);
79 fail("test should throw an exception");
80 } catch (Exception exc) {
81 assertEquals("model is marked @NonNull but is null", exc.getMessage());
85 PfModelService.registerModel(null, new DummyPfModel());
86 fail("test should throw an exception");
87 } catch (Exception exc) {
88 assertEquals("modelKey is marked @NonNull but is null", exc.getMessage());
92 PfModelService.deregisterModel(null);
93 fail("test should throw an exception");
94 } catch (Exception exc) {
95 assertEquals("modelKey is marked @NonNull but is null", exc.getMessage());
99 PfModelService.getModel(null);
100 fail("test should throw an exception");
101 } catch (Exception exc) {
102 assertEquals("modelKey is marked @NonNull but is null", exc.getMessage());