2 * ============LICENSE_START=======================================================
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
20 package org.onap.policy.drools.protocol.configuration;
22 import static org.junit.Assert.assertEquals;
23 import static org.junit.Assert.assertFalse;
24 import static org.junit.Assert.assertTrue;
26 import java.util.Properties;
28 import org.apache.commons.lang3.builder.HashCodeBuilder;
29 import org.junit.Test;
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";
37 private static final String NAME = "name";
38 private static final String OPERATION = "operation";
39 private static final String NAME2 = "name2";
40 private static final String OPERATION2 = "operation2";
42 private static final String ARTIFACT = "org.onap.artifact";
43 private static final String GROUPID = "group";
44 private static final String VERSION = "1.0.0";
46 private static final String ARTIFACT2 = "org.onap.artifact2";
47 private static final String GROUPID2 = "group2";
48 private static final String VERSION2 = "1.0.1";
50 private static final String ADDITIONAL_PROPERTY_KEY = "foo";
51 private static final String ADDITIONAL_PROPERTY_VALUE = "bar";
53 private static final DroolsConfiguration DROOLS_CONFIG = new DroolsConfiguration(ARTIFACT, GROUPID, VERSION);
54 private static final DroolsConfiguration DROOLS_CONFIG2 = new DroolsConfiguration(ARTIFACT2, GROUPID2, VERSION2);
60 Properties additionalProperties = new Properties();
61 additionalProperties.put(ADDITIONAL_PROPERTY_KEY, ADDITIONAL_PROPERTY_VALUE);
63 DroolsConfiguration droolsConfig = new DroolsConfiguration(ARTIFACT, GROUPID, VERSION);
64 assertTrue(droolsConfig.equals(droolsConfig));
66 droolsConfig.set(ARTIFACT_ID_STRING, "foobar");
67 assertEquals(droolsConfig.get(ARTIFACT_ID_STRING),"foobar");
69 assertEquals(droolsConfig.with(ARTIFACT_ID_STRING, "foobar2"), droolsConfig);
71 DroolsConfiguration droolsConfig2 = new DroolsConfiguration();
72 droolsConfig2.setArtifactId(ARTIFACT2);
73 droolsConfig2.setGroupId(GROUPID2);
74 droolsConfig2.setVersion(VERSION2);
76 assertEquals(droolsConfig2.getArtifactId(), ARTIFACT2);
77 assertEquals(droolsConfig2.getGroupId(), GROUPID2);
78 assertEquals(droolsConfig2.getVersion(), VERSION2);
80 assertEquals(droolsConfig2.withArtifactId(ARTIFACT2), droolsConfig2);
81 assertEquals(droolsConfig2.withGroupId(GROUPID2), droolsConfig2);
82 assertEquals(droolsConfig2.withVersion(VERSION2), droolsConfig2);
84 droolsConfig2.setAdditionalProperty(ADDITIONAL_PROPERTY_KEY, ADDITIONAL_PROPERTY_VALUE);
85 assertEquals(droolsConfig2.getAdditionalProperties(), additionalProperties);
87 assertEquals(droolsConfig2, droolsConfig2.withAdditionalProperty(ADDITIONAL_PROPERTY_KEY, ADDITIONAL_PROPERTY_VALUE));
89 assertTrue(droolsConfig2.declaredProperty(ARTIFACT_ID_STRING, ARTIFACT2));
90 assertTrue(droolsConfig2.declaredProperty(GROUP_ID_STRING, GROUPID2));
91 assertTrue(droolsConfig2.declaredProperty(VERSION_STRING, VERSION2));
92 assertFalse(droolsConfig2.declaredProperty("dummy", NAME));
94 assertEquals(droolsConfig2.declaredPropertyOrNotFound(ARTIFACT_ID_STRING, ARTIFACT2), ARTIFACT2);
95 assertEquals(droolsConfig2.declaredPropertyOrNotFound(GROUP_ID_STRING, GROUPID2), GROUPID2);
96 assertEquals(droolsConfig2.declaredPropertyOrNotFound(VERSION_STRING, VERSION2), VERSION2);
97 assertEquals(droolsConfig2.declaredPropertyOrNotFound("dummy", ARTIFACT2), ARTIFACT2);
99 int hashCode = new HashCodeBuilder().append(ARTIFACT2).append(GROUPID2).append(VERSION2).append(additionalProperties).toHashCode();
100 assertEquals(droolsConfig2.hashCode(), hashCode);