7d9b65514f5306ff02ac817e763549acac42c3cc
[policy/drools-pdp.git] /
1 /*-
2  * ============LICENSE_START=======================================================
3  * Configuration Test
4  * ================================================================================
5  * Copyright (C) 2017-2018 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.onap.policy.drools.protocol.configuration;
22
23 import static org.junit.Assert.assertEquals;
24 import static org.junit.Assert.assertFalse;
25 import static org.junit.Assert.assertTrue;
26
27 import java.util.Properties;
28
29 import org.apache.commons.lang3.builder.HashCodeBuilder;
30 import org.junit.Test;
31
32 public class DroolsConfigurationTest {
33     private static final String ARTIFACT_ID_STRING = "artifactId";
34     private static final String GROUP_ID_STRING = "groupId";
35     private static final String VERSION_STRING = "version";
36
37
38     private static final String NAME = "name";
39     private static final String ARTIFACT = "org.onap.artifact";
40     private static final String GROUPID = "group";
41     private static final String VERSION = "1.0.0";
42
43     private static final String ARTIFACT2 = "org.onap.artifact2";
44     private static final String GROUPID2 = "group2";
45     private static final String VERSION2 = "1.0.1";
46
47     private static final String ADDITIONAL_PROPERTY_KEY = "foo";
48     private static final String ADDITIONAL_PROPERTY_VALUE = "bar";
49
50     @Test
51     public void test() {
52         final Properties additionalProperties = new Properties();
53         additionalProperties.put(ADDITIONAL_PROPERTY_KEY, ADDITIONAL_PROPERTY_VALUE);
54
55         final DroolsConfiguration droolsConfig = new DroolsConfiguration(ARTIFACT, GROUPID, VERSION);
56         assertTrue(droolsConfig.equals(droolsConfig));
57
58         droolsConfig.set(ARTIFACT_ID_STRING, "foobar");
59         assertEquals(droolsConfig.get(ARTIFACT_ID_STRING), "foobar");
60
61         assertEquals(droolsConfig.with(ARTIFACT_ID_STRING, "foobar2"), droolsConfig);
62
63         final DroolsConfiguration droolsConfig2 = new DroolsConfiguration();
64         droolsConfig2.setArtifactId(ARTIFACT2);
65         droolsConfig2.setGroupId(GROUPID2);
66         droolsConfig2.setVersion(VERSION2);
67
68         assertEquals(droolsConfig2.getArtifactId(), ARTIFACT2);
69         assertEquals(droolsConfig2.getGroupId(), GROUPID2);
70         assertEquals(droolsConfig2.getVersion(), VERSION2);
71
72         assertEquals(droolsConfig2.withArtifactId(ARTIFACT2), droolsConfig2);
73         assertEquals(droolsConfig2.withGroupId(GROUPID2), droolsConfig2);
74         assertEquals(droolsConfig2.withVersion(VERSION2), droolsConfig2);
75
76         droolsConfig2.setAdditionalProperty(ADDITIONAL_PROPERTY_KEY, ADDITIONAL_PROPERTY_VALUE);
77         assertEquals(droolsConfig2.getAdditionalProperties(), additionalProperties);
78
79         assertEquals(droolsConfig2,
80                 droolsConfig2.withAdditionalProperty(ADDITIONAL_PROPERTY_KEY, ADDITIONAL_PROPERTY_VALUE));
81
82         assertTrue(droolsConfig2.declaredProperty(ARTIFACT_ID_STRING, ARTIFACT2));
83         assertTrue(droolsConfig2.declaredProperty(GROUP_ID_STRING, GROUPID2));
84         assertTrue(droolsConfig2.declaredProperty(VERSION_STRING, VERSION2));
85         assertFalse(droolsConfig2.declaredProperty("dummy", NAME));
86
87         assertEquals(droolsConfig2.declaredPropertyOrNotFound(ARTIFACT_ID_STRING, ARTIFACT2),
88                 ARTIFACT2);
89         assertEquals(droolsConfig2.declaredPropertyOrNotFound(GROUP_ID_STRING, GROUPID2), GROUPID2);
90         assertEquals(droolsConfig2.declaredPropertyOrNotFound(VERSION_STRING, VERSION2), VERSION2);
91         assertEquals(droolsConfig2.declaredPropertyOrNotFound("dummy", ARTIFACT2), ARTIFACT2);
92
93         final int hashCode = new HashCodeBuilder().append(ARTIFACT2).append(GROUPID2).append(VERSION2)
94                 .append(additionalProperties).toHashCode();
95         assertEquals(droolsConfig2.hashCode(), hashCode);
96     }
97 }