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.provider;
23 import static org.junit.Assert.assertEquals;
24 import static org.junit.Assert.fail;
26 import lombok.ToString;
28 import org.junit.Test;
31 * Test the {@link PolicyModelsProviderFactory} class.
33 * @author Liam Fallon (liam.fallon@est.tech)
36 public class PolicyModelsProviderFactoryTest {
39 public void testFactory() {
40 PolicyModelsProviderFactory factory = new PolicyModelsProviderFactory();
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());
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\"",
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());
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) {
76 "the class \"java.lang.String\" is not an implementation of the \"PolicyModelsProvider\" interface",
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());