Merge "Add models-pdp to models repo"
[policy/models.git] / models-provider / src / test / java / org / onap / policy / models / provider / PolicyModelsProviderFactoryTest.java
1 /*-
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
8  *
9  *      http://www.apache.org/licenses/LICENSE-2.0
10  *
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.
16  *
17  * SPDX-License-Identifier: Apache-2.0
18  * ============LICENSE_END=========================================================
19  */
20
21 package org.onap.policy.models.provider;
22
23 import static org.junit.Assert.assertEquals;
24 import static org.junit.Assert.fail;
25
26 import lombok.ToString;
27
28 import org.junit.Test;
29
30 /**
31  * Test the {@link PolicyModelsProviderFactory} class.
32  *
33  * @author Liam Fallon (liam.fallon@est.tech)
34  */
35 @ToString
36 public class PolicyModelsProviderFactoryTest {
37
38     @Test
39     public void testFactory() {
40         PolicyModelsProviderFactory factory = new PolicyModelsProviderFactory();
41
42         try {
43             factory.createPolicyModelsProvider(null);
44             fail("test should throw an exception here");
45         } catch (Exception exc) {
46             assertEquals("parameters is marked @NonNull but is null", exc.getMessage());
47         }
48
49         try {
50             PolicyModelsProviderParameters pars = new PolicyModelsProviderParameters();
51             pars.setImplementation(null);
52             factory.createPolicyModelsProvider(pars);
53             fail("test should throw an exception here");
54         } catch (Exception exc) {
55             assertEquals("could not find implementation of the \"PolicyModelsProvider\" interface \"null\"",
56                     exc.getMessage());
57         }
58
59         try {
60             PolicyModelsProviderParameters pars = new PolicyModelsProviderParameters();
61             pars.setImplementation("com.acmecorp.RoadRunner");
62             factory.createPolicyModelsProvider(pars);
63             fail("test should throw an exception here");
64         } catch (Exception exc) {
65             assertEquals("could not find implementation of the \"PolicyModelsProvider\" "
66                     + "interface \"com.acmecorp.RoadRunner\"", exc.getMessage());
67         }
68
69         try {
70             PolicyModelsProviderParameters pars = new PolicyModelsProviderParameters();
71             pars.setImplementation("java.lang.String");
72             factory.createPolicyModelsProvider(pars);
73             fail("test should throw an exception here");
74         } catch (Exception exc) {
75             assertEquals(
76                     "the class \"java.lang.String\" is not an implementation of the \"PolicyModelsProvider\" interface",
77                     exc.getMessage());
78         }
79
80         try {
81             PolicyModelsProviderParameters pars = new PolicyModelsProviderParameters();
82             pars.setImplementation("org.onap.policy.models.provider.impl.DummyBadProviderImpl");
83             factory.createPolicyModelsProvider(pars);
84             fail("test should throw an exception here");
85         } catch (Exception exc) {
86             assertEquals("could not create an instance of PolicyModelsProvider "
87                     + "\"org.onap.policy.models.provider.impl.DummyBadProviderImpl\"", exc.getMessage());
88         }
89     }
90 }