You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@metron.apache.org by mm...@apache.org on 2016/10/11 14:57:06 UTC
incubator-metron git commit: METRON-439: Stellar : IS_EMPTY(host)
throws exception (mmiklavc) closes apache/incubator-metron#296
Repository: incubator-metron
Updated Branches:
refs/heads/master 6277d28c8 -> f1065a62f
METRON-439: Stellar : IS_EMPTY(host) throws exception (mmiklavc) closes apache/incubator-metron#296
Project: http://git-wip-us.apache.org/repos/asf/incubator-metron/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-metron/commit/f1065a62
Tree: http://git-wip-us.apache.org/repos/asf/incubator-metron/tree/f1065a62
Diff: http://git-wip-us.apache.org/repos/asf/incubator-metron/diff/f1065a62
Branch: refs/heads/master
Commit: f1065a62f1016b84e0faed364eece504edb473ef
Parents: 6277d28
Author: mmiklavc <mi...@gmail.com>
Authored: Tue Oct 11 10:56:39 2016 -0400
Committer: Michael Miklavcic <mi...@gmail.com>
Committed: Tue Oct 11 10:56:39 2016 -0400
----------------------------------------------------------------------
.../dsl/functions/DataStructureFunctions.java | 6 +-
.../functions/DataStructureFunctionsTest.java | 62 ++++++++++++++++++++
2 files changed, 65 insertions(+), 3 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-metron/blob/f1065a62/metron-platform/metron-common/src/main/java/org/apache/metron/common/dsl/functions/DataStructureFunctions.java
----------------------------------------------------------------------
diff --git a/metron-platform/metron-common/src/main/java/org/apache/metron/common/dsl/functions/DataStructureFunctions.java b/metron-platform/metron-common/src/main/java/org/apache/metron/common/dsl/functions/DataStructureFunctions.java
index be373f5..567df88 100644
--- a/metron-platform/metron-common/src/main/java/org/apache/metron/common/dsl/functions/DataStructureFunctions.java
+++ b/metron-platform/metron-common/src/main/java/org/apache/metron/common/dsl/functions/DataStructureFunctions.java
@@ -146,8 +146,8 @@ public class DataStructureFunctions {
@Override
public Object apply(List<Object> list) {
- if(list.size() == 0) {
- throw new IllegalStateException("IS_EMPTY expects one string arg");
+ if(null == list || list.size() == 0) {
+ return true;
}
Object o = list.get(0);
if(o instanceof Collection) {
@@ -158,7 +158,7 @@ public class DataStructureFunctions {
return val == null || val.isEmpty() ? true : false;
}
else {
- throw new IllegalStateException("IS_EMPTY expects a collection or string");
+ return true;
}
}
}
http://git-wip-us.apache.org/repos/asf/incubator-metron/blob/f1065a62/metron-platform/metron-common/src/test/java/org/apache/metron/common/dsl/functions/DataStructureFunctionsTest.java
----------------------------------------------------------------------
diff --git a/metron-platform/metron-common/src/test/java/org/apache/metron/common/dsl/functions/DataStructureFunctionsTest.java b/metron-platform/metron-common/src/test/java/org/apache/metron/common/dsl/functions/DataStructureFunctionsTest.java
new file mode 100644
index 0000000..01c9439
--- /dev/null
+++ b/metron-platform/metron-common/src/test/java/org/apache/metron/common/dsl/functions/DataStructureFunctionsTest.java
@@ -0,0 +1,62 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.
+ */
+
+package org.apache.metron.common.dsl.functions;
+
+import com.google.common.collect.ImmutableList;
+import org.hamcrest.CoreMatchers;
+import org.junit.Assert;
+import org.junit.Test;
+
+public class DataStructureFunctionsTest {
+
+ @Test
+ public void is_empty_handles_happy_path() {
+ DataStructureFunctions.IsEmpty isEmpty = new DataStructureFunctions.IsEmpty();
+ {
+ boolean empty = (boolean) isEmpty.apply(ImmutableList.of("hello"));
+ Assert.assertThat("should be false", empty, CoreMatchers.equalTo(false));
+ }
+ {
+ boolean empty = (boolean) isEmpty.apply(ImmutableList.of(ImmutableList.of("hello", "world")));
+ Assert.assertThat("should be false", empty, CoreMatchers.equalTo(false));
+ }
+ }
+
+ @Test
+ public void is_empty_handles_empty_values() {
+ DataStructureFunctions.IsEmpty isEmpty = new DataStructureFunctions.IsEmpty();
+ {
+ boolean empty = (boolean) isEmpty.apply(ImmutableList.of());
+ Assert.assertThat("should be true", empty, CoreMatchers.equalTo(true));
+ }
+ {
+ boolean empty = (boolean) isEmpty.apply(null);
+ Assert.assertThat("should be true", empty, CoreMatchers.equalTo(true));
+ }
+ {
+ boolean empty = (boolean) isEmpty.apply(ImmutableList.of(""));
+ Assert.assertThat("should be true", empty, CoreMatchers.equalTo(true));
+ }
+ {
+ boolean empty = (boolean) isEmpty.apply(ImmutableList.of(new Object()));
+ Assert.assertThat("should be true", empty, CoreMatchers.equalTo(true));
+ }
+ }
+
+}