summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authork.kedron <k.kedron@partner.samsung.com>2019-06-12 17:44:31 +0200
committerOfir Sonsino <ofir.sonsino@intl.att.com>2019-06-17 07:17:41 +0000
commitcb1980df76d96cb1157c60fecb6a6101b09ab9ae (patch)
tree27ef45b68463ae78154726abdce3901d62d18b47
parent6159cb862e49b2ab8b06c11b159681beaf7cbd89 (diff)
Improve unit tests for TopoSearchAction.
Issue-ID: SDC-2327 Signed-off-by: Krystian Kedron <k.kedron@partner.samsung.com> Change-Id: I1edf0e2739f1a14eaa097c4ac9a420d4405d3da2
-rw-r--r--src/test/java/org/onap/sdc/dcae/composition/restmodels/ruleeditor/TopoSearchActionTest.java158
1 files changed, 155 insertions, 3 deletions
diff --git a/src/test/java/org/onap/sdc/dcae/composition/restmodels/ruleeditor/TopoSearchActionTest.java b/src/test/java/org/onap/sdc/dcae/composition/restmodels/ruleeditor/TopoSearchActionTest.java
index 23efb05..d052d26 100644
--- a/src/test/java/org/onap/sdc/dcae/composition/restmodels/ruleeditor/TopoSearchActionTest.java
+++ b/src/test/java/org/onap/sdc/dcae/composition/restmodels/ruleeditor/TopoSearchActionTest.java
@@ -1,12 +1,72 @@
+/*-
+ * ============LICENSE_START===============================================
+ * ONAP SDC
+ * ========================================================================
+ * Modifications Copyright (c) 2019 Samsung
+ * ========================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=================================================
+ */
+
package org.onap.sdc.dcae.composition.restmodels.ruleeditor;
-import org.junit.Test;
+import static com.google.code.beanmatchers.BeanMatchers.hasValidBeanConstructor;
+import static com.google.code.beanmatchers.BeanMatchers.hasValidBeanEquals;
+import static com.google.code.beanmatchers.BeanMatchers.hasValidBeanHashCodeFor;
+import static com.google.code.beanmatchers.BeanMatchers.hasValidGettersAndSetters;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertThat;
+import static org.junit.Assert.assertTrue;
+
+import com.google.gson.Gson;
+import com.google.gson.GsonBuilder;
+
+import java.util.List;
+import java.util.Map;
-import static com.google.code.beanmatchers.BeanMatchers.*;
-import static org.junit.Assert.*;
+import org.junit.Test;
public class TopoSearchActionTest {
+ private static Gson gson = new GsonBuilder()
+ .registerTypeAdapter(BaseAction.class, new ActionDeserializer())
+ .registerTypeAdapter(BaseCondition.class, new ConditionDeserializer()).create();
+
+ private static final String ACTION_TYPE = "Test Topology Search";
+ private static final String ID = "123";
+ private static final String SEARCH_FIELD = "sourceToSearch";
+ private static final String SEARCH_STRING = "searchString";
+ private static final String SEARCH_VALUE = "${"+ SEARCH_STRING +"}";
+ private static final String RADIO = "1234";
+ private static final String SEARCH_FILTER_LEFT = "${event.commonEventHeader.eventId}";
+ private static final String SEARCH_FILTER_RIGHT_ITEM = "testItem";
+ private static final String SEARCH_FILTER_RIGHT_ARRAY = "["+ SEARCH_FILTER_RIGHT_ITEM +"]";
+ private static final String SEARCH_FILTER_OPERATOR = "TestOperator";
+ private static final String ENRICH_FIELD1 = "enrichFiled1";
+ private static final String ENRICH_FIELD2 = "enrichField2";
+ private static final String ENRICH_FIELDS_ARRAY = "[{value:"+ ENRICH_FIELD1 +"},{value:"+ ENRICH_FIELD2 +"}]";
+ private static final String ENRICH_PREFIX = "enrichPrefix";
+
+ private static final String UI_HASH_MAP_KEY1 = "testKey1";
+ private static final String UI_HASH_MAP_KEY2 = "testKey2";
+ private static final String UI_HASH_MAP_VALUE1 = "test1";
+ private static final String UI_HASH_MAP_VALUE2 = "test2";
+
+ private static final String BAD_STRIPPED_TARGET = "badTarget";
+
@Test
public void shouldHaveValidGettersAndSetters() {
assertThat(TopoSearchAction.class, hasValidGettersAndSetters());
@@ -27,5 +87,97 @@ public class TopoSearchActionTest {
assertThat(TopoSearchAction.class, hasValidBeanHashCodeFor());
}
+ @Test
+ public void topSearchActionBaseFieldTest() {
+ TopoSearchAction topoSearchAction = buildBaseConditionalTopoSearchAction();
+
+ assertEquals(SEARCH_FIELD, topoSearchAction.searchField());
+ assertEquals(SEARCH_VALUE, topoSearchAction.searchValue());
+ assertNotNull(topoSearchAction.searchFilter());
+
+ Condition filter = topoSearchAction.searchFilter();
+ assertEquals(SEARCH_FILTER_LEFT, filter.left);
+ assertEquals(SEARCH_FILTER_RIGHT_ITEM, filter.right.get(0));
+ assertEquals(SEARCH_FILTER_OPERATOR, filter.operator);
+
+ assertEquals(ENRICH_PREFIX, topoSearchAction.enrichPrefix());
+ assertNotNull(topoSearchAction.enrichFields());
+
+ List<String> enrichFields = topoSearchAction.enrichFields();
+ assertEquals(ENRICH_FIELD1, enrichFields.get(0));
+ assertEquals(ENRICH_FIELD2, enrichFields.get(1));
+
+ assertTrue(topoSearchAction.doEnrich());
+ }
+
+ @Test
+ public void topSearchActionUpdatesTest() {
+ TopoSearchAction topoSearchAction = buildConditionalTopoSearchActionWithUpdates();
+ assertNotNull(topoSearchAction.updates());
+
+ List<BaseAction.UIHashMap> uiHashMapList = topoSearchAction.updates();
+ assertEquals(UI_HASH_MAP_VALUE1, uiHashMapList.get(0).getValue());
+ assertEquals(UI_HASH_MAP_VALUE2, uiHashMapList.get(1).getValue());
+ assertEquals(UI_HASH_MAP_KEY1, uiHashMapList.get(0).getKey());
+ assertEquals(UI_HASH_MAP_KEY2, uiHashMapList.get(1).getKey());
+ Map<String, String> updatesMap = topoSearchAction.updatesMap();
+ assertEquals(UI_HASH_MAP_VALUE1, updatesMap.get(UI_HASH_MAP_KEY1));
+ assertEquals(UI_HASH_MAP_VALUE2, updatesMap.get(UI_HASH_MAP_KEY2));
+ }
+
+ @Test
+ public void checkReferencesTargetTest() {
+ TopoSearchAction topoSearchAction = buildBaseConditionalTopoSearchAction();
+
+ BaseAction baseAction = new TestBaseAction(SEARCH_STRING);
+ BaseAction baseActionWithBadTarget = new TestBaseAction(BAD_STRIPPED_TARGET);
+
+ assertTrue(topoSearchAction.referencesTarget(baseAction));
+ assertFalse(topoSearchAction.referencesTarget(baseActionWithBadTarget));
+ }
+
+ private TopoSearchAction buildBaseConditionalTopoSearchAction() {
+ String topoSearch = "{actionType:\"" + ACTION_TYPE + "\"," +
+ "id:" + ID + "," +
+ "search:{searchField:" + SEARCH_FIELD + "," +
+ "searchValue:\"" + SEARCH_VALUE + "\"," +
+ "radio:" + RADIO + "," +
+ "searchFilter:{left:\"" + SEARCH_FILTER_LEFT + "\"," +
+ "right:" + SEARCH_FILTER_RIGHT_ARRAY + "," +
+ "operator:" + SEARCH_FILTER_OPERATOR + "}," +
+ "enrich:{fields:" + ENRICH_FIELDS_ARRAY + "," +
+ "prefix:" + ENRICH_PREFIX + "}}}";
+ return buildTopoSearchAction(topoSearch);
+ }
+
+ private TopoSearchAction buildConditionalTopoSearchActionWithUpdates() {
+ String topoSearch = "{search:{updates: [{key:" + UI_HASH_MAP_KEY1 + ", value:" + UI_HASH_MAP_VALUE1 + "}," +
+ "{key:" + UI_HASH_MAP_KEY2 + ", value:" + UI_HASH_MAP_VALUE2 + "}]}}";
+
+ return buildTopoSearchAction(topoSearch);
+ }
+
+ private TopoSearchAction buildTopoSearchAction(String topoSearch) {
+ return gson.fromJson(topoSearch, TopoSearchAction.class);
+ }
+
+ private class TestBaseAction extends BaseAction {
+
+ private String strippedTarget;
+
+ TestBaseAction(String strippedTarget) {
+ this.strippedTarget = strippedTarget;
+ }
+
+ @Override
+ public boolean referencesTarget(BaseAction other) {
+ return false;
+ }
+
+ @Override
+ public String strippedTarget() {
+ return strippedTarget;
+ }
+ }
} \ No newline at end of file