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