http://git-wip-us.apache.org/repos/asf/metron/blob/a5b13777/metron-platform/metron-common/src/test/java/org/apache/metron/common/stellar/evaluators/ComparisonOperatorsEvaluatorTest.java ---------------------------------------------------------------------- diff --git a/metron-platform/metron-common/src/test/java/org/apache/metron/common/stellar/evaluators/ComparisonOperatorsEvaluatorTest.java b/metron-platform/metron-common/src/test/java/org/apache/metron/common/stellar/evaluators/ComparisonOperatorsEvaluatorTest.java deleted file mode 100644 index 3617e44..0000000 --- a/metron-platform/metron-common/src/test/java/org/apache/metron/common/stellar/evaluators/ComparisonOperatorsEvaluatorTest.java +++ /dev/null @@ -1,446 +0,0 @@ -/* - * 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.stellar.evaluators; - -import org.antlr.v4.runtime.tree.TerminalNode; -import org.apache.metron.common.dsl.ParseException; -import org.apache.metron.common.dsl.Token; -import org.apache.metron.common.stellar.generated.StellarParser; -import org.junit.Before; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.ExpectedException; - -import java.io.Serializable; - -import static org.junit.Assert.*; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; - -@SuppressWarnings("ALL") -public class ComparisonOperatorsEvaluatorTest { - @Rule - public final ExpectedException exception = ExpectedException.none(); - - ComparisonExpressionEvaluator evaluator; - - @Before - public void setUp() throws Exception { - evaluator = new ComparisonOperatorsEvaluator(); - } - - @Test - public void nonSupportedOperatorThrowsExceptionNonNumbericComparable() throws Exception { - Token<String> left = mock(Token.class); - when(left.getValue()).thenReturn("b"); - - Token<String> right = mock(Token.class); - when(right.getValue()).thenReturn("a"); - - StellarParser.ComparisonOpContext op = mock(StellarParser.ComparisonOpContext.class); - - exception.expect(ParseException.class); - exception.expectMessage("Unsupported operator: " + op); - - evaluator.evaluate(left, right, op); - } - - @Test - public void nonSupportedOperatorThrowsExceptionNumbericComparison() throws Exception { - Token<Long> left = mock(Token.class); - when(left.getValue()).thenReturn(1L); - - Token<Long> right = mock(Token.class); - when(right.getValue()).thenReturn(0L); - - StellarParser.ComparisonOpContext op = mock(StellarParser.ComparisonOpContext.class); - - exception.expect(ParseException.class); - exception.expectMessage("Unsupported operator: " + op); - - evaluator.evaluate(left, right, op); - } - - @Test - public void leftIsNullThenThrowException() throws Exception { - Token<Long> left = mock(Token.class); - Token<Long> right = mock(Token.class); - when(right.getValue()).thenReturn(1L); - - StellarParser.ComparisonOpContext op = mock(StellarParser.ComparisonOpContext.class); - when(op.LT()).thenReturn(mock(TerminalNode.class)); - - assertFalse(evaluator.evaluate(left, right, op)); - } - - @Test - public void rightIsNullThenReturnFalse() throws Exception { - Token<Long> left = mock(Token.class); - when(left.getValue()).thenReturn(1L); - Token<Long> right = mock(Token.class); - - StellarParser.ComparisonOpContext op = mock(StellarParser.ComparisonOpContext.class); - when(op.LT()).thenReturn(mock(TerminalNode.class)); - - assertFalse(evaluator.evaluate(left, right, op)); - } - - @Test - public void rightAndLeftIsNullThenReturnFalse() throws Exception { - Token<Long> left = mock(Token.class); - Token<Long> right = mock(Token.class); - - StellarParser.ComparisonOpContext op = mock(StellarParser.ComparisonOpContext.class); - when(op.LT()).thenReturn(mock(TerminalNode.class)); - - assertFalse(evaluator.evaluate(left, right, op)); - } - - @Test - public void throwParseExceptionWhenTryingToCompareNonComparable() throws Exception { - exception.expect(ParseException.class); - exception.expectMessage("Unsupported operations. The following expression is invalid: "); - - Token<Serializable> left = mock(Token.class); - when(left.getValue()).thenReturn(mock(Serializable.class)); - - Token<Serializable> right = mock(Token.class); - when(right.getValue()).thenReturn(mock(Serializable.class)); - - StellarParser.ComparisonOpContext op = mock(StellarParser.ComparisonOpContext.class); - when(op.LT()).thenReturn(mock(TerminalNode.class)); - - evaluator.evaluate(left, right, op); - } - - @Test - public void makeSureAllOperatorsProperlyWorkForLongs() throws Exception { - Token<Long> left = mock(Token.class); - when(left.getValue()).thenReturn(0L); - - Token<Long> right = mock(Token.class); - when(right.getValue()).thenReturn(1L); - - { - StellarParser.ComparisonOpContext op = mock(StellarParser.ComparisonOpContext.class); - when(op.LT()).thenReturn(mock(TerminalNode.class)); - assertTrue(evaluator.evaluate(left, right, op)); - } - { - StellarParser.ComparisonOpContext op = mock(StellarParser.ComparisonOpContext.class); - when(op.LTE()).thenReturn(mock(TerminalNode.class)); - assertTrue(evaluator.evaluate(left, right, op)); - } - { - StellarParser.ComparisonOpContext op = mock(StellarParser.ComparisonOpContext.class); - when(op.GT()).thenReturn(mock(TerminalNode.class)); - assertFalse(evaluator.evaluate(left, right, op)); - } - { - StellarParser.ComparisonOpContext op = mock(StellarParser.ComparisonOpContext.class); - when(op.GTE()).thenReturn(mock(TerminalNode.class)); - assertFalse(evaluator.evaluate(left, right, op)); - } - } - - @Test - public void makeSureAllOperatorsProperlyWorkForDoubles() throws Exception { - Token<Double> left = mock(Token.class); - when(left.getValue()).thenReturn(0D); - - Token<Double> right = mock(Token.class); - when(right.getValue()).thenReturn(1D); - - { - StellarParser.ComparisonOpContext op = mock(StellarParser.ComparisonOpContext.class); - when(op.LT()).thenReturn(mock(TerminalNode.class)); - assertTrue(evaluator.evaluate(left, right, op)); - } - { - StellarParser.ComparisonOpContext op = mock(StellarParser.ComparisonOpContext.class); - when(op.LTE()).thenReturn(mock(TerminalNode.class)); - assertTrue(evaluator.evaluate(left, right, op)); - } - { - StellarParser.ComparisonOpContext op = mock(StellarParser.ComparisonOpContext.class); - when(op.GT()).thenReturn(mock(TerminalNode.class)); - assertFalse(evaluator.evaluate(left, right, op)); - } - { - StellarParser.ComparisonOpContext op = mock(StellarParser.ComparisonOpContext.class); - when(op.GTE()).thenReturn(mock(TerminalNode.class)); - assertFalse(evaluator.evaluate(left, right, op)); - } - } - - @Test - public void makeSureAllOperatorsProperlyWorkForFloats() throws Exception { - Token<Float> left = mock(Token.class); - when(left.getValue()).thenReturn(0F); - - Token<Float> right = mock(Token.class); - when(right.getValue()).thenReturn(1F); - - { - StellarParser.ComparisonOpContext op = mock(StellarParser.ComparisonOpContext.class); - when(op.LT()).thenReturn(mock(TerminalNode.class)); - assertTrue(evaluator.evaluate(left, right, op)); - } - { - StellarParser.ComparisonOpContext op = mock(StellarParser.ComparisonOpContext.class); - when(op.LTE()).thenReturn(mock(TerminalNode.class)); - assertTrue(evaluator.evaluate(left, right, op)); - } - { - StellarParser.ComparisonOpContext op = mock(StellarParser.ComparisonOpContext.class); - when(op.GT()).thenReturn(mock(TerminalNode.class)); - assertFalse(evaluator.evaluate(left, right, op)); - } - { - StellarParser.ComparisonOpContext op = mock(StellarParser.ComparisonOpContext.class); - when(op.GTE()).thenReturn(mock(TerminalNode.class)); - assertFalse(evaluator.evaluate(left, right, op)); - } - } - - @Test - public void makeSureAllOperatorsProperlyWorkForInts() throws Exception { - Token<Integer> left = mock(Token.class); - when(left.getValue()).thenReturn(0); - - Token<Integer> right = mock(Token.class); - when(right.getValue()).thenReturn(1); - - { - StellarParser.ComparisonOpContext op = mock(StellarParser.ComparisonOpContext.class); - when(op.LT()).thenReturn(mock(TerminalNode.class)); - assertTrue(evaluator.evaluate(left, right, op)); - } - { - StellarParser.ComparisonOpContext op = mock(StellarParser.ComparisonOpContext.class); - when(op.LTE()).thenReturn(mock(TerminalNode.class)); - assertTrue(evaluator.evaluate(left, right, op)); - } - { - StellarParser.ComparisonOpContext op = mock(StellarParser.ComparisonOpContext.class); - when(op.GT()).thenReturn(mock(TerminalNode.class)); - assertFalse(evaluator.evaluate(left, right, op)); - } - { - StellarParser.ComparisonOpContext op = mock(StellarParser.ComparisonOpContext.class); - when(op.GTE()).thenReturn(mock(TerminalNode.class)); - assertFalse(evaluator.evaluate(left, right, op)); - } - } - - @Test - public void makeSureAllOperatorsWorkForMixedTypesDoublesLong() throws Exception { - Token<Long> left = mock(Token.class); - when(left.getValue()).thenReturn(1L); - - Token<Double> right = mock(Token.class); - when(right.getValue()).thenReturn(1.0000001D); - - { - StellarParser.ComparisonOpContext op = mock(StellarParser.ComparisonOpContext.class); - when(op.LT()).thenReturn(mock(TerminalNode.class)); - assertTrue(evaluator.evaluate(left, right, op)); - } - { - StellarParser.ComparisonOpContext op = mock(StellarParser.ComparisonOpContext.class); - when(op.LTE()).thenReturn(mock(TerminalNode.class)); - assertTrue(evaluator.evaluate(left, right, op)); - } - { - StellarParser.ComparisonOpContext op = mock(StellarParser.ComparisonOpContext.class); - when(op.GT()).thenReturn(mock(TerminalNode.class)); - assertFalse(evaluator.evaluate(left, right, op)); - } - { - StellarParser.ComparisonOpContext op = mock(StellarParser.ComparisonOpContext.class); - when(op.GTE()).thenReturn(mock(TerminalNode.class)); - assertFalse(evaluator.evaluate(left, right, op)); - } - } - - @Test - public void makeSureAllOperatorsWorkForMixedTypesDoublesFloat() throws Exception { - final double leftValue = 1.0000001D; - final float rightValue = 1.0000001F; - - Token<Double> left = mock(Token.class); - when(left.getValue()).thenReturn(leftValue); - - Token<Float> right = mock(Token.class); - when(right.getValue()).thenReturn(rightValue); - - { - StellarParser.ComparisonOpContext op = mock(StellarParser.ComparisonOpContext.class); - when(op.LT()).thenReturn(mock(TerminalNode.class)); - assertEquals(leftValue < rightValue, evaluator.evaluate(left, right, op)); - } - { - StellarParser.ComparisonOpContext op = mock(StellarParser.ComparisonOpContext.class); - when(op.LTE()).thenReturn(mock(TerminalNode.class)); - assertEquals(leftValue <= rightValue, evaluator.evaluate(left, right, op)); - } - { - StellarParser.ComparisonOpContext op = mock(StellarParser.ComparisonOpContext.class); - when(op.GT()).thenReturn(mock(TerminalNode.class)); - assertEquals(leftValue > rightValue, evaluator.evaluate(left, right, op)); - } - { - StellarParser.ComparisonOpContext op = mock(StellarParser.ComparisonOpContext.class); - when(op.GTE()).thenReturn(mock(TerminalNode.class)); - assertEquals(leftValue >= rightValue, evaluator.evaluate(left, right, op)); - } - } - - @Test - public void makeSureAllOperatorsWorkForMixedTypesFloatIntegers() throws Exception { - final int leftValue = 1; - final float rightValue = 1.0000001F; - - Token<Integer> left = mock(Token.class); - when(left.getValue()).thenReturn(leftValue); - - Token<Float> right = mock(Token.class); - when(right.getValue()).thenReturn(rightValue); - - { - StellarParser.ComparisonOpContext op = mock(StellarParser.ComparisonOpContext.class); - when(op.LT()).thenReturn(mock(TerminalNode.class)); - assertEquals(leftValue < rightValue, evaluator.evaluate(left, right, op)); - } - { - StellarParser.ComparisonOpContext op = mock(StellarParser.ComparisonOpContext.class); - when(op.LTE()).thenReturn(mock(TerminalNode.class)); - assertEquals(leftValue <= rightValue, evaluator.evaluate(left, right, op)); - } - { - StellarParser.ComparisonOpContext op = mock(StellarParser.ComparisonOpContext.class); - when(op.GT()).thenReturn(mock(TerminalNode.class)); - assertEquals(leftValue > rightValue, evaluator.evaluate(left, right, op)); - } - { - StellarParser.ComparisonOpContext op = mock(StellarParser.ComparisonOpContext.class); - when(op.GTE()).thenReturn(mock(TerminalNode.class)); - assertEquals(leftValue >= rightValue, evaluator.evaluate(left, right, op)); - } - } - - @Test - public void makeSureAllOperatorsWorkForMixedTypesFloatIntegers2() throws Exception { - final int leftValue = 1; - final float rightValue = 1.00000001F; - - Token<Integer> left = mock(Token.class); - when(left.getValue()).thenReturn(leftValue); - - Token<Float> right = mock(Token.class); - when(right.getValue()).thenReturn(rightValue); - - { - StellarParser.ComparisonOpContext op = mock(StellarParser.ComparisonOpContext.class); - when(op.LT()).thenReturn(mock(TerminalNode.class)); - assertEquals(leftValue < rightValue, evaluator.evaluate(left, right, op)); - } - { - StellarParser.ComparisonOpContext op = mock(StellarParser.ComparisonOpContext.class); - when(op.LTE()).thenReturn(mock(TerminalNode.class)); - assertEquals(leftValue <= rightValue, evaluator.evaluate(left, right, op)); - } - { - StellarParser.ComparisonOpContext op = mock(StellarParser.ComparisonOpContext.class); - when(op.GT()).thenReturn(mock(TerminalNode.class)); - assertEquals(leftValue > rightValue, evaluator.evaluate(left, right, op)); - } - { - StellarParser.ComparisonOpContext op = mock(StellarParser.ComparisonOpContext.class); - when(op.GTE()).thenReturn(mock(TerminalNode.class)); - assertEquals(leftValue >= rightValue, evaluator.evaluate(left, right, op)); - } - } - - @Test - public void makeSureAllOperatorsWorkForMixedTypesLongIntegers() throws Exception { - final int leftValue = 1; - final long rightValue = 3L; - - Token<Integer> left = mock(Token.class); - when(left.getValue()).thenReturn(leftValue); - - Token<Long> right = mock(Token.class); - when(right.getValue()).thenReturn(rightValue); - - { - StellarParser.ComparisonOpContext op = mock(StellarParser.ComparisonOpContext.class); - when(op.LT()).thenReturn(mock(TerminalNode.class)); - assertEquals(leftValue < rightValue, evaluator.evaluate(left, right, op)); - } - { - StellarParser.ComparisonOpContext op = mock(StellarParser.ComparisonOpContext.class); - when(op.LTE()).thenReturn(mock(TerminalNode.class)); - assertEquals(leftValue <= rightValue, evaluator.evaluate(left, right, op)); - } - { - StellarParser.ComparisonOpContext op = mock(StellarParser.ComparisonOpContext.class); - when(op.GT()).thenReturn(mock(TerminalNode.class)); - assertEquals(leftValue > rightValue, evaluator.evaluate(left, right, op)); - } - { - StellarParser.ComparisonOpContext op = mock(StellarParser.ComparisonOpContext.class); - when(op.GTE()).thenReturn(mock(TerminalNode.class)); - assertEquals(leftValue >= rightValue, evaluator.evaluate(left, right, op)); - } - } - - @Test - public void makeSureAllOperatorsWorkForNonIntegerComparableTypes() throws Exception { - final String leftValue = "a"; - final String rightValue = "b"; - - Token<String> left = mock(Token.class); - when(left.getValue()).thenReturn(leftValue); - - Token<String> right = mock(Token.class); - when(right.getValue()).thenReturn(rightValue); - - { - StellarParser.ComparisonOpContext op = mock(StellarParser.ComparisonOpContext.class); - when(op.LT()).thenReturn(mock(TerminalNode.class)); - assertEquals(leftValue.compareTo(rightValue) < 0, evaluator.evaluate(left, right, op)); - } - { - StellarParser.ComparisonOpContext op = mock(StellarParser.ComparisonOpContext.class); - when(op.LTE()).thenReturn(mock(TerminalNode.class)); - assertEquals(leftValue.compareTo(rightValue) <= 0, evaluator.evaluate(left, right, op)); - } - { - StellarParser.ComparisonOpContext op = mock(StellarParser.ComparisonOpContext.class); - when(op.GT()).thenReturn(mock(TerminalNode.class)); - assertEquals(leftValue.compareTo(rightValue) > 0, evaluator.evaluate(left, right, op)); - } - { - StellarParser.ComparisonOpContext op = mock(StellarParser.ComparisonOpContext.class); - when(op.GTE()).thenReturn(mock(TerminalNode.class)); - assertEquals(leftValue.compareTo(rightValue) >= 0, evaluator.evaluate(left, right, op)); - } - } -} \ No newline at end of file
http://git-wip-us.apache.org/repos/asf/metron/blob/a5b13777/metron-platform/metron-common/src/test/java/org/apache/metron/common/stellar/evaluators/DoubleLiteralEvaluatorTest.java ---------------------------------------------------------------------- diff --git a/metron-platform/metron-common/src/test/java/org/apache/metron/common/stellar/evaluators/DoubleLiteralEvaluatorTest.java b/metron-platform/metron-common/src/test/java/org/apache/metron/common/stellar/evaluators/DoubleLiteralEvaluatorTest.java deleted file mode 100644 index 3386f3f..0000000 --- a/metron-platform/metron-common/src/test/java/org/apache/metron/common/stellar/evaluators/DoubleLiteralEvaluatorTest.java +++ /dev/null @@ -1,70 +0,0 @@ -/* - * 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.stellar.evaluators; - -import org.apache.metron.common.dsl.Token; -import org.apache.metron.common.stellar.generated.StellarParser; -import org.junit.Before; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.ExpectedException; - -import static org.junit.Assert.assertEquals; -import static org.mockito.Mockito.*; - -public class DoubleLiteralEvaluatorTest { - @Rule - public final ExpectedException exception = ExpectedException.none(); - - NumberEvaluator<StellarParser.DoubleLiteralContext> evaluator; - StellarParser.DoubleLiteralContext context; - - @Before - public void setUp() throws Exception { - evaluator = new DoubleLiteralEvaluator(); - context = mock(StellarParser.DoubleLiteralContext.class); - } - - @Test - public void verifyHappyPathEvaluation() throws Exception { - when(context.getText()).thenReturn("100D"); - - Token<? extends Number> evaluated = evaluator.evaluate(context, null); - assertEquals(new Token<>(100D, Double.class, null), evaluated); - - verify(context).getText(); - verifyNoMoreInteractions(context); - } - - @Test - public void verifyNumberFormationExceptionWithEmptyString() throws Exception { - exception.expect(NumberFormatException.class); - - when(context.getText()).thenReturn(""); - evaluator.evaluate(context, null); - } - - @Test - public void throwIllegalArgumentExceptionWhenContextIsNull() throws Exception { - exception.expect(IllegalArgumentException.class); - exception.expectMessage("Cannot evaluate a context that is null."); - - evaluator.evaluate(null, null); - } -} http://git-wip-us.apache.org/repos/asf/metron/blob/a5b13777/metron-platform/metron-common/src/test/java/org/apache/metron/common/stellar/evaluators/EqualityOperatorsEvaluatorTest.java ---------------------------------------------------------------------- diff --git a/metron-platform/metron-common/src/test/java/org/apache/metron/common/stellar/evaluators/EqualityOperatorsEvaluatorTest.java b/metron-platform/metron-common/src/test/java/org/apache/metron/common/stellar/evaluators/EqualityOperatorsEvaluatorTest.java deleted file mode 100644 index efa7db6..0000000 --- a/metron-platform/metron-common/src/test/java/org/apache/metron/common/stellar/evaluators/EqualityOperatorsEvaluatorTest.java +++ /dev/null @@ -1,186 +0,0 @@ -/* - * 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.stellar.evaluators; - -import org.antlr.v4.runtime.tree.TerminalNode; -import org.apache.metron.common.dsl.Token; -import org.apache.metron.common.stellar.generated.StellarParser; -import org.junit.Before; -import org.junit.Test; - -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; - -@SuppressWarnings({"unchecked"}) -public class EqualityOperatorsEvaluatorTest { - ComparisonExpressionEvaluator evaluator; - - @Before - public void setUp() throws Exception { - evaluator = new EqualityOperatorsEvaluator(); - } - - @Test - public void leftAndRightNullShouldBeTrue() throws Exception { - Token<Double> left = mock(Token.class); - when(left.getValue()).thenReturn(null); - - Token<Double> right = mock(Token.class); - when(right.getValue()).thenReturn(null); - - StellarParser.ComparisonOpContext op = mock(StellarParser.ComparisonOpContext.class); - when(op.EQ()).thenReturn(mock(TerminalNode.class)); - - boolean evaluated = evaluator.evaluate(left, right, op); - - assertTrue(evaluated); - } - - @Test - public void leftNullAndRightNotShouldBeFalse() throws Exception { - Token<Double> left = mock(Token.class); - when(left.getValue()).thenReturn(null); - - Token<Double> right = mock(Token.class); - when(right.getValue()).thenReturn(1D); - - StellarParser.ComparisonOpContext op = mock(StellarParser.ComparisonOpContext.class); - when(op.EQ()).thenReturn(mock(TerminalNode.class)); - - boolean evaluated = evaluator.evaluate(left, right, op); - - assertFalse(evaluated); - } - - @Test - public void leftNotNullAndRightNullShouldBeFalse() throws Exception { - Token<Double> left = mock(Token.class); - when(left.getValue()).thenReturn(1D); - - Token<Long> right = mock(Token.class); - when(right.getValue()).thenReturn(null); - - StellarParser.ComparisonOpContext op = mock(StellarParser.ComparisonOpContext.class); - when(op.EQ()).thenReturn(mock(TerminalNode.class)); - - boolean evaluated = evaluator.evaluate(left, right, op); - - assertFalse(evaluated); - } - - @Test - public void eqTestForTwoLongs() throws Exception { - Token<Long> left = mock(Token.class); - when(left.getValue()).thenReturn(1L); - - Token<Long> right = mock(Token.class); - when(right.getValue()).thenReturn(1L); - - StellarParser.ComparisonOpContext op = mock(StellarParser.ComparisonOpContext.class); - when(op.EQ()).thenReturn(mock(TerminalNode.class)); - - assertTrue(evaluator.evaluate(left, right, op)); - } - - @Test - public void eqTestForTwoDoubles() throws Exception { - Token<Double> left = mock(Token.class); - when(left.getValue()).thenReturn(1D); - - Token<Double> right = mock(Token.class); - when(right.getValue()).thenReturn(1D); - - StellarParser.ComparisonOpContext op = mock(StellarParser.ComparisonOpContext.class); - when(op.EQ()).thenReturn(mock(TerminalNode.class)); - - assertTrue(evaluator.evaluate(left, right, op)); - } - - @Test - public void eqTestForTwoFloats() throws Exception { - Token<Float> left = mock(Token.class); - when(left.getValue()).thenReturn(1F); - - Token<Float> right = mock(Token.class); - when(right.getValue()).thenReturn(1F); - - StellarParser.ComparisonOpContext op = mock(StellarParser.ComparisonOpContext.class); - when(op.EQ()).thenReturn(mock(TerminalNode.class)); - - assertTrue(evaluator.evaluate(left, right, op)); - } - - @Test - public void eqTestForTwoIntegers() throws Exception { - Token<Integer> left = mock(Token.class); - when(left.getValue()).thenReturn(1); - - Token<Integer> right = mock(Token.class); - when(right.getValue()).thenReturn(1); - - StellarParser.ComparisonOpContext op = mock(StellarParser.ComparisonOpContext.class); - when(op.EQ()).thenReturn(mock(TerminalNode.class)); - - assertTrue(evaluator.evaluate(left, right, op)); - } - - @Test - public void eqTestForTwoStrings() throws Exception { - Token<String> left = mock(Token.class); - when(left.getValue()).thenReturn("1"); - - Token<String> right = mock(Token.class); - when(right.getValue()).thenReturn("1"); - - StellarParser.ComparisonOpContext op = mock(StellarParser.ComparisonOpContext.class); - when(op.EQ()).thenReturn(mock(TerminalNode.class)); - - assertTrue(evaluator.evaluate(left, right, op)); - } - - @Test - public void eqTestForUnlikeTypes() throws Exception { - Token<String> left = mock(Token.class); - when(left.getValue()).thenReturn("1"); - - Token<Long> right = mock(Token.class); - when(right.getValue()).thenReturn(1L); - - StellarParser.ComparisonOpContext op = mock(StellarParser.ComparisonOpContext.class); - when(op.EQ()).thenReturn(mock(TerminalNode.class)); - - assertFalse(evaluator.evaluate(left, right, op)); - } - - @Test - public void eqTestForUnlikeTypesLongString() throws Exception { - Token<Long> left = mock(Token.class); - when(left.getValue()).thenReturn(1L); - - Token<String> right = mock(Token.class); - when(right.getValue()).thenReturn("1"); - - StellarParser.ComparisonOpContext op = mock(StellarParser.ComparisonOpContext.class); - when(op.EQ()).thenReturn(mock(TerminalNode.class)); - - assertFalse(evaluator.evaluate(left, right, op)); - } -} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/metron/blob/a5b13777/metron-platform/metron-common/src/test/java/org/apache/metron/common/stellar/evaluators/FloatLiteralEvaluatorTest.java ---------------------------------------------------------------------- diff --git a/metron-platform/metron-common/src/test/java/org/apache/metron/common/stellar/evaluators/FloatLiteralEvaluatorTest.java b/metron-platform/metron-common/src/test/java/org/apache/metron/common/stellar/evaluators/FloatLiteralEvaluatorTest.java deleted file mode 100644 index f9ecff1..0000000 --- a/metron-platform/metron-common/src/test/java/org/apache/metron/common/stellar/evaluators/FloatLiteralEvaluatorTest.java +++ /dev/null @@ -1,74 +0,0 @@ -/* - * 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.stellar.evaluators; - -import org.apache.metron.common.dsl.Token; -import org.apache.metron.common.stellar.generated.StellarParser; -import org.junit.Before; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.ExpectedException; - -import static org.junit.Assert.assertEquals; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.verifyNoMoreInteractions; -import static org.mockito.Mockito.when; - -public class FloatLiteralEvaluatorTest { - @Rule - public final ExpectedException exception = ExpectedException.none(); - - NumberEvaluator<StellarParser.FloatLiteralContext> evaluator; - StellarParser.FloatLiteralContext context; - - @Before - public void setUp() throws Exception { - evaluator = new FloatLiteralEvaluator(); - context = mock(StellarParser.FloatLiteralContext.class); - } - - @Test - public void verifyHappyPathEvaluation() throws Exception { - when(context.getText()).thenReturn("100f"); - - Token<? extends Number> evaluated = evaluator.evaluate(context, null); - assertEquals(new Token<>(100f, Float.class, null), evaluated); - - verify(context).getText(); - verifyNoMoreInteractions(context); - } - - @Test - public void verifyNumberFormationExceptionWithEmptyString() throws Exception { - exception.expect(NumberFormatException.class); - - when(context.getText()).thenReturn(""); - evaluator.evaluate(context, null); - } - - @Test - public void throwIllegalArgumentExceptionWhenContextIsNull() throws Exception { - exception.expect(IllegalArgumentException.class); - exception.expectMessage("Cannot evaluate a context that is null."); - - evaluator.evaluate(null, null); - } - -} http://git-wip-us.apache.org/repos/asf/metron/blob/a5b13777/metron-platform/metron-common/src/test/java/org/apache/metron/common/stellar/evaluators/IntLiteralEvaluatorTest.java ---------------------------------------------------------------------- diff --git a/metron-platform/metron-common/src/test/java/org/apache/metron/common/stellar/evaluators/IntLiteralEvaluatorTest.java b/metron-platform/metron-common/src/test/java/org/apache/metron/common/stellar/evaluators/IntLiteralEvaluatorTest.java deleted file mode 100644 index bef23d1..0000000 --- a/metron-platform/metron-common/src/test/java/org/apache/metron/common/stellar/evaluators/IntLiteralEvaluatorTest.java +++ /dev/null @@ -1,74 +0,0 @@ -/* - * 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.stellar.evaluators; - -import org.apache.metron.common.dsl.Token; -import org.apache.metron.common.stellar.generated.StellarParser; -import org.junit.Before; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.ExpectedException; - -import static org.junit.Assert.assertEquals; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.verifyNoMoreInteractions; -import static org.mockito.Mockito.when; - -public class IntLiteralEvaluatorTest { - @Rule - public final ExpectedException exception = ExpectedException.none(); - - NumberEvaluator<StellarParser.IntLiteralContext> evaluator; - StellarParser.IntLiteralContext context; - - @Before - public void setUp() throws Exception { - evaluator = new IntLiteralEvaluator(); - context = mock(StellarParser.IntLiteralContext.class); - } - - @Test - public void verifyHappyPathEvaluation() throws Exception { - when(context.getText()).thenReturn("100"); - - Token<? extends Number> evaluated = evaluator.evaluate(context, null); - assertEquals(new Token<>(100, Integer.class, null), evaluated); - - verify(context).getText(); - verifyNoMoreInteractions(context); - } - - @Test - public void verifyNumberFormationExceptionWithEmptyString() throws Exception { - exception.expect(NumberFormatException.class); - - when(context.getText()).thenReturn(""); - evaluator.evaluate(context, null); - } - - @Test - public void throwIllegalArgumentExceptionWhenContextIsNull() throws Exception { - exception.expect(IllegalArgumentException.class); - exception.expectMessage("Cannot evaluate a context that is null."); - - evaluator.evaluate(null, null); - } - -} http://git-wip-us.apache.org/repos/asf/metron/blob/a5b13777/metron-platform/metron-common/src/test/java/org/apache/metron/common/stellar/evaluators/LongLiteralEvaluatorTest.java ---------------------------------------------------------------------- diff --git a/metron-platform/metron-common/src/test/java/org/apache/metron/common/stellar/evaluators/LongLiteralEvaluatorTest.java b/metron-platform/metron-common/src/test/java/org/apache/metron/common/stellar/evaluators/LongLiteralEvaluatorTest.java deleted file mode 100644 index e9c3aa7..0000000 --- a/metron-platform/metron-common/src/test/java/org/apache/metron/common/stellar/evaluators/LongLiteralEvaluatorTest.java +++ /dev/null @@ -1,75 +0,0 @@ -/* - * 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.stellar.evaluators; - -import org.apache.metron.common.dsl.ParseException; -import org.apache.metron.common.dsl.Token; -import org.apache.metron.common.stellar.generated.StellarParser; -import org.junit.Before; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.ExpectedException; - -import static org.junit.Assert.assertEquals; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.verifyNoMoreInteractions; -import static org.mockito.Mockito.when; - -public class LongLiteralEvaluatorTest { - @Rule - public final ExpectedException exception = ExpectedException.none(); - - NumberEvaluator<StellarParser.LongLiteralContext> evaluator; - StellarParser.LongLiteralContext context; - - @Before - public void setUp() throws Exception { - evaluator = new LongLiteralEvaluator(); - context = mock(StellarParser.LongLiteralContext.class); - } - - @Test - public void verifyHappyPathEvaluation() throws Exception { - when(context.getText()).thenReturn("100L"); - - Token<? extends Number> evaluated = evaluator.evaluate(context, null); - assertEquals(new Token<>(100L, Long.class, null), evaluated); - - verify(context).getText(); - verifyNoMoreInteractions(context); - } - - @Test - public void verifyNumberFormationExceptionWithEmptyString() throws Exception { - exception.expect(ParseException.class); - exception.expectMessage("Invalid format for long. Failed trying to parse a long with the following value: "); - - when(context.getText()).thenReturn(""); - evaluator.evaluate(context, null); - } - - @Test - public void throwIllegalArgumentExceptionWhenContextIsNull() throws Exception { - exception.expect(IllegalArgumentException.class); - exception.expectMessage("Cannot evaluate a context that is null."); - - evaluator.evaluate(null, null); - } -} http://git-wip-us.apache.org/repos/asf/metron/blob/a5b13777/metron-platform/metron-common/src/test/java/org/apache/metron/common/stellar/evaluators/NumberLiteralEvaluatorTest.java ---------------------------------------------------------------------- diff --git a/metron-platform/metron-common/src/test/java/org/apache/metron/common/stellar/evaluators/NumberLiteralEvaluatorTest.java b/metron-platform/metron-common/src/test/java/org/apache/metron/common/stellar/evaluators/NumberLiteralEvaluatorTest.java deleted file mode 100644 index 2065e6d..0000000 --- a/metron-platform/metron-common/src/test/java/org/apache/metron/common/stellar/evaluators/NumberLiteralEvaluatorTest.java +++ /dev/null @@ -1,107 +0,0 @@ -/* - * 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.stellar.evaluators; - -import org.apache.metron.common.dsl.ParseException; -import org.apache.metron.common.stellar.generated.StellarParser; -import org.junit.Before; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.ExpectedException; - -import java.util.HashMap; -import java.util.Map; - -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.verifyZeroInteractions; - -public class NumberLiteralEvaluatorTest { - NumberEvaluator<StellarParser.IntLiteralContext> intLiteralContextNumberEvaluator; - NumberEvaluator<StellarParser.DoubleLiteralContext> doubleLiteralContextNumberEvaluator; - NumberEvaluator<StellarParser.FloatLiteralContext> floatLiteralContextNumberEvaluator; - NumberEvaluator<StellarParser.LongLiteralContext> longLiteralContextNumberEvaluator; - - Map<Class<? extends StellarParser.Arithmetic_operandsContext>, NumberEvaluator> instanceMap; - - @Rule - public final ExpectedException exception = ExpectedException.none(); - - @Before - public void setUp() throws Exception { - intLiteralContextNumberEvaluator = mock(IntLiteralEvaluator.class); - doubleLiteralContextNumberEvaluator = mock(DoubleLiteralEvaluator.class); - floatLiteralContextNumberEvaluator = mock(FloatLiteralEvaluator.class); - longLiteralContextNumberEvaluator = mock(LongLiteralEvaluator.class); - instanceMap = new HashMap<Class<? extends StellarParser.Arithmetic_operandsContext>, NumberEvaluator>() {{ - put(mock(StellarParser.IntLiteralContext.class).getClass(), intLiteralContextNumberEvaluator); - put(mock(StellarParser.DoubleLiteralContext.class).getClass(), doubleLiteralContextNumberEvaluator); - put(mock(StellarParser.FloatLiteralContext.class).getClass(), floatLiteralContextNumberEvaluator); - put(mock(StellarParser.LongLiteralContext.class).getClass(), longLiteralContextNumberEvaluator); - }}; - } - - @Test - public void verifyIntLiteralContextIsProperlyEvaluated() throws Exception { - StellarParser.IntLiteralContext context = mock(StellarParser.IntLiteralContext.class); - NumberLiteralEvaluator.INSTANCE.evaluate(context, instanceMap, null); - - verify(intLiteralContextNumberEvaluator).evaluate(context, null); - verifyZeroInteractions(doubleLiteralContextNumberEvaluator, floatLiteralContextNumberEvaluator, longLiteralContextNumberEvaluator); - } - - @Test - public void verifyDoubleLiteralContextIsProperlyEvaluated() throws Exception { - StellarParser.DoubleLiteralContext context = mock(StellarParser.DoubleLiteralContext.class); - NumberLiteralEvaluator.INSTANCE.evaluate(context, instanceMap, null); - - verify(doubleLiteralContextNumberEvaluator).evaluate(context, null); - verifyZeroInteractions(intLiteralContextNumberEvaluator, floatLiteralContextNumberEvaluator, longLiteralContextNumberEvaluator); - } - - @Test - public void verifyFloatLiteralContextIsProperlyEvaluated() throws Exception { - StellarParser.FloatLiteralContext context = mock(StellarParser.FloatLiteralContext.class); - NumberLiteralEvaluator.INSTANCE.evaluate(context, instanceMap, null); - - verify(floatLiteralContextNumberEvaluator).evaluate(context, null); - verifyZeroInteractions(doubleLiteralContextNumberEvaluator, intLiteralContextNumberEvaluator, longLiteralContextNumberEvaluator); - } - - @Test - public void verifyLongLiteralContextIsProperlyEvaluated() throws Exception { - StellarParser.LongLiteralContext context = mock(StellarParser.LongLiteralContext.class); - NumberLiteralEvaluator.INSTANCE.evaluate(context, instanceMap, null); - - verify(longLiteralContextNumberEvaluator).evaluate(context, null); - verifyZeroInteractions(doubleLiteralContextNumberEvaluator, floatLiteralContextNumberEvaluator, intLiteralContextNumberEvaluator); - } - - @Test - public void verifyExceptionThrownForUnsupportedContextType() throws Exception { - StellarParser.VariableContext context = mock(StellarParser.VariableContext.class); - - exception.expect(ParseException.class); - exception.expectMessage("Does not support evaluation for type " + context.getClass()); - - NumberLiteralEvaluator.INSTANCE.evaluate(context, instanceMap, null); - - verifyZeroInteractions(longLiteralContextNumberEvaluator, doubleLiteralContextNumberEvaluator, floatLiteralContextNumberEvaluator, intLiteralContextNumberEvaluator); - } -} http://git-wip-us.apache.org/repos/asf/metron/blob/a5b13777/metron-platform/metron-common/src/test/java/org/apache/metron/common/stellar/maas/MockDGAModel.java ---------------------------------------------------------------------- diff --git a/metron-platform/metron-common/src/test/java/org/apache/metron/common/stellar/maas/MockDGAModel.java b/metron-platform/metron-common/src/test/java/org/apache/metron/common/stellar/maas/MockDGAModel.java deleted file mode 100644 index 0373c27..0000000 --- a/metron-platform/metron-common/src/test/java/org/apache/metron/common/stellar/maas/MockDGAModel.java +++ /dev/null @@ -1,83 +0,0 @@ -/** - * 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.stellar.maas; - -import com.fasterxml.jackson.core.JsonProcessingException; -import com.google.common.collect.ImmutableMap; -import com.sun.net.httpserver.HttpHandler; -import com.sun.net.httpserver.HttpServer; -import org.apache.metron.common.utils.JSONUtils; - -import javax.ws.rs.*; -import javax.ws.rs.core.Application; -import javax.ws.rs.core.MediaType; -import javax.ws.rs.core.Response; -import javax.ws.rs.core.UriBuilder; -import javax.ws.rs.ext.RuntimeDelegate; -import java.io.IOException; -import java.net.InetSocketAddress; -import java.net.URI; -import java.util.*; - -@Path("/") -public class MockDGAModel { - private static HttpServer server; - private Map<String, Boolean> isMalicious = ImmutableMap.of( "badguy.com", true - ); - - @GET - @Path("/apply") - @Produces("application/json") - public Response apply(@QueryParam("host") String host ) throws JsonProcessingException { - Boolean b = isMalicious.get(host); - boolean isMalicious = b != null && b; - Map<String, Boolean> ret = new HashMap<String, Boolean>(); - ret.put("is_malicious", isMalicious ); - String resp = JSONUtils.INSTANCE.toJSON(ret, true); - return Response.ok(resp, MediaType.APPLICATION_JSON_TYPE).build(); - } - - @ApplicationPath("rs") - public static class ApplicationConfig extends Application { - private final Set<Class<?>> classes; - public ApplicationConfig() { - HashSet<Class<?>> c = new HashSet<>(); - c.add(MockDGAModel.class); - classes = Collections.unmodifiableSet(c); - } - @Override - public Set<Class<?>> getClasses() { - return classes; - } - } - - public static void start(int port) throws IOException { - // Create an HTTP server listening at port - URI uri = UriBuilder.fromUri("http://localhost/").port(port).build(); - server = HttpServer.create(new InetSocketAddress(uri.getPort()), 0); - HttpHandler handler = RuntimeDelegate.getInstance().createEndpoint(new ApplicationConfig(), HttpHandler.class); - server.createContext(uri.getPath(), handler); - server.start(); - } - - public static void shutdown() { - if(server != null) { - server.stop(0); - } - } -} http://git-wip-us.apache.org/repos/asf/metron/blob/a5b13777/metron-platform/metron-common/src/test/java/org/apache/metron/common/stellar/maas/StellarMaaSIntegrationTest.java ---------------------------------------------------------------------- diff --git a/metron-platform/metron-common/src/test/java/org/apache/metron/common/stellar/maas/StellarMaaSIntegrationTest.java b/metron-platform/metron-common/src/test/java/org/apache/metron/common/stellar/maas/StellarMaaSIntegrationTest.java deleted file mode 100644 index 0896d86..0000000 --- a/metron-platform/metron-common/src/test/java/org/apache/metron/common/stellar/maas/StellarMaaSIntegrationTest.java +++ /dev/null @@ -1,181 +0,0 @@ -/** - * 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.stellar.maas; - -import com.google.common.collect.ImmutableMap; -import com.sun.jersey.server.impl.application.WebApplicationImpl; -import org.apache.curator.RetryPolicy; -import org.apache.curator.framework.CuratorFramework; -import org.apache.curator.framework.CuratorFrameworkFactory; -import org.apache.curator.retry.ExponentialBackoffRetry; -import org.apache.curator.test.TestingServer; -import org.apache.curator.utils.CloseableUtils; -import org.apache.curator.x.discovery.ServiceInstance; -import org.apache.curator.x.discovery.ServiceInstanceBuilder; -import org.apache.curator.x.discovery.ServiceType; -import org.apache.metron.common.dsl.Context; -import org.apache.metron.maas.config.Endpoint; -import org.apache.metron.maas.config.MaaSConfig; -import org.apache.metron.maas.config.ModelEndpoint; -import org.apache.metron.maas.discovery.ServiceDiscoverer; -import org.apache.metron.maas.util.ConfigUtil; -import org.apache.metron.test.utils.UnitTestHelper; -import org.junit.*; - -import java.net.URL; -import java.util.HashMap; -import java.util.Map; -import java.util.logging.Level; - -import static org.apache.metron.common.utils.StellarProcessorUtils.run; - -public class StellarMaaSIntegrationTest { - private static Context context; - private static TestingServer testZkServer; - private static String zookeeperUrl; - private static CuratorFramework client; - private static ServiceDiscoverer discoverer; - private static URL endpointUrl; - - @BeforeClass - public static void setup() throws Exception { - UnitTestHelper.setJavaLoggingLevel(WebApplicationImpl.class, Level.WARNING); - MockDGAModel.start(8282); - testZkServer = new TestingServer(true); - zookeeperUrl = testZkServer.getConnectString(); - RetryPolicy retryPolicy = new ExponentialBackoffRetry(1000, 3); - client = CuratorFrameworkFactory.newClient(zookeeperUrl, retryPolicy); - client.start(); - context = new Context.Builder() - .with(Context.Capabilities.ZOOKEEPER_CLIENT, () -> client) - .build(); - MaaSConfig config = ConfigUtil.INSTANCE.read(client, "/metron/maas/config", new MaaSConfig(), MaaSConfig.class); - discoverer = new ServiceDiscoverer(client, config.getServiceRoot()); - discoverer.start(); - endpointUrl = new URL("http://localhost:8282"); - ModelEndpoint endpoint = new ModelEndpoint(); - { - endpoint.setName("dga"); - endpoint.setContainerId("0"); - Endpoint ep = new Endpoint(); - ep.setUrl(endpointUrl.toString()); - endpoint.setEndpoint(ep); - endpoint.setVersion("1.0"); - } - ; - - ServiceInstanceBuilder<ModelEndpoint> builder = ServiceInstance.<ModelEndpoint>builder() - .address(endpointUrl.getHost()) - .id("0") - .name("dga") - .port(endpointUrl.getPort()) - .registrationTimeUTC(System.currentTimeMillis()) - .serviceType(ServiceType.STATIC) - .payload(endpoint); - final ServiceInstance<ModelEndpoint> instance = builder.build(); - discoverer.getServiceDiscovery().registerService(instance); - //wait til the endpoint is installed... - for(int i = 0;i < 10;++i) { - try { - Object o = discoverer.getEndpoint("dga"); - if(o != null) { - break; - } - } - catch(Exception e) { - - } - Thread.sleep(1000); - } - } - - @Test - public void testGetEndpointWithoutVersion() throws Exception { - String stellar = "MAAS_GET_ENDPOINT('dga')"; - Object result = run(stellar, new HashMap<>(), context); - Assert.assertTrue(result instanceof Map); - Map<String, String> resMap = (Map<String, String>)result; - Assert.assertEquals(resMap.get("url"), "http://localhost:8282"); - Assert.assertEquals(resMap.get("name"), "dga"); - Assert.assertEquals(resMap.get("version"), "1.0"); - Assert.assertEquals(resMap.get("endpoint:apply"), "apply"); - - } - - @Test - public void testGetEndpointWithVersion() throws Exception { - String stellar = "MAAS_GET_ENDPOINT('dga', '1.0')"; - Object result = run(stellar, new HashMap<>(), context); - Assert.assertTrue(result instanceof Map); - Map<String, String> resMap = (Map<String, String>)result; - Assert.assertEquals(resMap.get("url"), "http://localhost:8282"); - Assert.assertEquals(resMap.get("name"), "dga"); - Assert.assertEquals(resMap.get("version"), "1.0"); - Assert.assertEquals(resMap.get("endpoint:apply"), "apply"); - } - - @Test - public void testGetEndpointWithWrongVersion() throws Exception { - String stellar = "MAAS_GET_ENDPOINT('dga', '2.0')"; - Object result = run(stellar, new HashMap<>(), context); - Assert.assertNull(result); - } - - @Test - public void testModelApply() throws Exception { - { - String stellar = "MAP_GET('is_malicious', MAAS_MODEL_APPLY(MAAS_GET_ENDPOINT('dga'), {'host': host}))"; - Object result = run(stellar, ImmutableMap.of("host", "badguy.com"), context); - Assert.assertTrue((Boolean) result); - } - { - String stellar = "MAP_GET('is_malicious', MAAS_MODEL_APPLY(MAAS_GET_ENDPOINT('dga'), {'host': host}))"; - Object result = run(stellar, ImmutableMap.of("host", "youtube.com"), context); - Assert.assertFalse((Boolean) result); - } - { - String stellar = "MAP_GET('is_malicious', MAAS_MODEL_APPLY(MAAS_GET_ENDPOINT('dga'), 'apply', {'host': host}))"; - Object result = run(stellar, ImmutableMap.of("host", "youtube.com"), context); - Assert.assertFalse((Boolean) result); - } - - } - - @Test - public void testModelApplyNegative() { - { - String stellar = "MAP_GET('is_malicious', MAAS_MODEL_APPLY(MAAS_GET_ENDPOINT('dga', '2.0'), {'host': host}))"; - Object result = run(stellar, ImmutableMap.of("host", "youtube.com"), context); - Assert.assertNull( result); - } - } - - @AfterClass - public static void teardown() { - MockDGAModel.shutdown(); - if(discoverer != null) { - CloseableUtils.closeQuietly(discoverer); - } - if(client != null) { - CloseableUtils.closeQuietly(client); - } - if(testZkServer != null) { - CloseableUtils.closeQuietly(testZkServer); - } - } -} http://git-wip-us.apache.org/repos/asf/metron/blob/a5b13777/metron-platform/metron-common/src/test/java/org/apache/metron/common/stellar/network/NetworkFunctionsTest.java ---------------------------------------------------------------------- diff --git a/metron-platform/metron-common/src/test/java/org/apache/metron/common/stellar/network/NetworkFunctionsTest.java b/metron-platform/metron-common/src/test/java/org/apache/metron/common/stellar/network/NetworkFunctionsTest.java deleted file mode 100644 index d43d6fd..0000000 --- a/metron-platform/metron-common/src/test/java/org/apache/metron/common/stellar/network/NetworkFunctionsTest.java +++ /dev/null @@ -1,156 +0,0 @@ -/** - * 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.stellar.network; - -import com.google.common.collect.ImmutableList; -import org.junit.Test; - - -import static org.apache.metron.common.utils.StellarProcessorUtils.runWithArguments; - -public class NetworkFunctionsTest { - - @Test - public void inSubnetTest_positive() { - runWithArguments("IN_SUBNET", ImmutableList.of("192.168.0.1", "192.168.0.0/24"), true); - } - - @Test - public void inSubnetTest_negative() { - runWithArguments("IN_SUBNET", ImmutableList.of("192.168.1.1", "192.168.0.0/24"), false); - } - - @Test - public void inSubnetTest_multiple() { - runWithArguments("IN_SUBNET", ImmutableList.of("192.168.1.1", "192.168.0.0/24", "192.168.1.0/24"), true); - } - - @Test - public void removeSubdomainsTest() { - runWithArguments("DOMAIN_REMOVE_SUBDOMAINS", "www.google.co.uk", "google.co.uk"); - runWithArguments("DOMAIN_REMOVE_SUBDOMAINS", "www.google.com", "google.com"); - runWithArguments("DOMAIN_REMOVE_SUBDOMAINS", "com", "com"); - } - - @Test - public void removeSubdomainsTest_tld_square() { - runWithArguments("DOMAIN_REMOVE_SUBDOMAINS", "com.com", "com.com"); - runWithArguments("DOMAIN_REMOVE_SUBDOMAINS", "net.net", "net.net"); - runWithArguments("DOMAIN_REMOVE_SUBDOMAINS", "co.uk.co.uk", "uk.co.uk"); - runWithArguments("DOMAIN_REMOVE_SUBDOMAINS", "www.subdomain.com.com", "com.com"); - } - - @Test - public void removeSubdomainsTest_unknowntld() { - runWithArguments("DOMAIN_REMOVE_SUBDOMAINS", "www.subdomain.google.gmail", "google.gmail"); - } - - @Test - public void toTldTest() { - runWithArguments("DOMAIN_TO_TLD", "www.google.co.uk", "co.uk"); - runWithArguments("DOMAIN_TO_TLD", "www.google.com", "com"); - runWithArguments("DOMAIN_TO_TLD", "com", "com"); - } - - @Test - public void toTldTest_tld_square() { - runWithArguments("DOMAIN_TO_TLD", "com.com", "com"); - runWithArguments("DOMAIN_TO_TLD", "net.net", "net"); - runWithArguments("DOMAIN_TO_TLD", "co.uk.co.uk", "co.uk"); - runWithArguments("DOMAIN_TO_TLD", "www.subdomain.com.com", "com"); - } - - @Test - public void toTldTest_unknowntld() { - runWithArguments("DOMAIN_TO_TLD", "www.subdomain.google.gmail", "gmail"); - } - - @Test - public void removeTldTest() { - runWithArguments("DOMAIN_REMOVE_TLD", "google.com", "google"); - runWithArguments("DOMAIN_REMOVE_TLD", "www.google.co.uk", "www.google"); - runWithArguments("DOMAIN_REMOVE_TLD", "www.google.com", "www.google"); - runWithArguments("DOMAIN_REMOVE_TLD", "com", ""); - } - - @Test - public void removeTldTest_tld_square() { - runWithArguments("DOMAIN_REMOVE_TLD", "com.com", "com"); - runWithArguments("DOMAIN_REMOVE_TLD", "net.net", "net"); - runWithArguments("DOMAIN_REMOVE_TLD", "co.uk.co.uk", "co.uk"); - runWithArguments("DOMAIN_REMOVE_TLD", "www.subdomain.com.com", "www.subdomain.com"); - } - - @Test - public void removeTldTest_unknowntld() { - runWithArguments("DOMAIN_REMOVE_TLD", "www.subdomain.google.gmail", "www.subdomain.google"); - } - - @Test - public void urlToPortTest() { - runWithArguments("URL_TO_PORT", "http://www.google.com/foo/bar", 80); - runWithArguments("URL_TO_PORT", "https://www.google.com/foo/bar", 443); - runWithArguments("URL_TO_PORT", "http://www.google.com:7979/foo/bar", 7979); - } - - - @Test - public void urlToPortTest_unknowntld() { - runWithArguments("URL_TO_PORT", "http://www.google.gmail/foo/bar", 80); - } - - @Test - public void urlToHostTest() { - runWithArguments("URL_TO_HOST", "http://www.google.com/foo/bar", "www.google.com"); - runWithArguments("URL_TO_HOST", "https://www.google.com/foo/bar", "www.google.com"); - runWithArguments("URL_TO_HOST", "http://www.google.com:7979/foo/bar", "www.google.com"); - runWithArguments("URL_TO_HOST", "http://localhost:8080/a", "localhost"); - } - - - @Test - public void urlToHostTest_unknowntld() { - runWithArguments("URL_TO_HOST", "http://www.google.gmail/foo/bar", "www.google.gmail"); - } - - @Test - public void urlToProtocolTest() { - runWithArguments("URL_TO_PROTOCOL", "http://www.google.com/foo/bar", "http"); - runWithArguments("URL_TO_PROTOCOL", "https://www.google.com/foo/bar", "https"); - } - - - @Test - public void urlToProtocolTest_unknowntld() { - runWithArguments("URL_TO_PROTOCOL", "http://www.google.gmail/foo/bar", "http"); - } - - @Test - public void urlToPathTest() { - runWithArguments("URL_TO_PATH", "http://www.google.com/foo/bar", "/foo/bar"); - runWithArguments("URL_TO_PATH", "https://www.google.com/foo/bar", "/foo/bar"); - } - - - @Test - public void urlToPathTest_unknowntld() { - runWithArguments("URL_TO_PATH", "http://www.google.gmail/foo/bar", "/foo/bar"); - } - - -} http://git-wip-us.apache.org/repos/asf/metron/blob/a5b13777/metron-platform/metron-common/src/test/java/org/apache/metron/common/utils/ConversionUtilsTest.java ---------------------------------------------------------------------- diff --git a/metron-platform/metron-common/src/test/java/org/apache/metron/common/utils/ConversionUtilsTest.java b/metron-platform/metron-common/src/test/java/org/apache/metron/common/utils/ConversionUtilsTest.java deleted file mode 100644 index 7c825a1..0000000 --- a/metron-platform/metron-common/src/test/java/org/apache/metron/common/utils/ConversionUtilsTest.java +++ /dev/null @@ -1,34 +0,0 @@ -/** - * 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.utils; - -import org.junit.Assert; -import org.junit.Test; - -public class ConversionUtilsTest { - - @Test - public void testIntegerConversions() { - Object o = 1; - Assert.assertEquals(Integer.valueOf(1), ConversionUtils.convert(o, Integer.class)); - Assert.assertEquals(Integer.valueOf(1), ConversionUtils.convert("1", Integer.class)); - Assert.assertNull(ConversionUtils.convert("foo", Integer.class)); - } - -} http://git-wip-us.apache.org/repos/asf/metron/blob/a5b13777/metron-platform/metron-common/src/test/java/org/apache/metron/common/utils/SerDeUtilsTest.java ---------------------------------------------------------------------- diff --git a/metron-platform/metron-common/src/test/java/org/apache/metron/common/utils/SerDeUtilsTest.java b/metron-platform/metron-common/src/test/java/org/apache/metron/common/utils/SerDeUtilsTest.java index 88ce664..8ccc2f4 100644 --- a/metron-platform/metron-common/src/test/java/org/apache/metron/common/utils/SerDeUtilsTest.java +++ b/metron-platform/metron-common/src/test/java/org/apache/metron/common/utils/SerDeUtilsTest.java @@ -21,6 +21,7 @@ package org.apache.metron.common.utils; import com.google.common.collect.ImmutableList; +import org.apache.metron.stellar.common.utils.BloomFilter; import org.junit.Assert; import org.junit.Test; http://git-wip-us.apache.org/repos/asf/metron/blob/a5b13777/metron-platform/metron-common/src/test/java/org/apache/metron/common/utils/StellarProcessorUtils.java ---------------------------------------------------------------------- diff --git a/metron-platform/metron-common/src/test/java/org/apache/metron/common/utils/StellarProcessorUtils.java b/metron-platform/metron-common/src/test/java/org/apache/metron/common/utils/StellarProcessorUtils.java deleted file mode 100644 index 8a8e32a..0000000 --- a/metron-platform/metron-common/src/test/java/org/apache/metron/common/utils/StellarProcessorUtils.java +++ /dev/null @@ -1,159 +0,0 @@ -/** - * 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.utils; - -import org.apache.metron.common.dsl.Context; -import org.apache.metron.common.dsl.MapVariableResolver; -import org.apache.metron.common.dsl.StellarFunctions; -import org.apache.metron.common.dsl.VariableResolver; -import com.google.common.collect.ImmutableList; -import org.apache.metron.common.stellar.StellarPredicateProcessor; -import org.apache.metron.common.stellar.StellarProcessor; -import org.junit.Assert; - -import java.util.AbstractMap; -import java.util.List; -import java.util.Map; -import java.util.Spliterators; -import java.util.function.Consumer; -import java.util.function.IntConsumer; -import java.util.function.Supplier; -import java.util.stream.Collectors; -import java.util.stream.Stream; -import java.util.stream.StreamSupport; - -public class StellarProcessorUtils { - - /** - * This ensures the basic contract of a stellar expression is adhered to: - * 1. Validate works on the expression - * 2. The output can be serialized and deserialized properly - * - * @param rule - * @param variables - * @param context - * @return - */ - public static Object run(String rule, Map<String, Object> variables, Context context) { - StellarProcessor processor = new StellarProcessor(); - Assert.assertTrue(rule + " not valid.", processor.validate(rule, context)); - Object ret = processor.parse(rule, x -> variables.get(x), StellarFunctions.FUNCTION_RESOLVER(), context); - byte[] raw = SerDeUtils.toBytes(ret); - Object actual = SerDeUtils.fromBytes(raw, Object.class); - Assert.assertEquals(ret, actual); - return ret; - } - - public static Object run(String rule, Map<String, Object> variables) { - return run(rule, variables, Context.EMPTY_CONTEXT()); - } - - public static boolean runPredicate(String rule, Map resolver) { - return runPredicate(rule, resolver, Context.EMPTY_CONTEXT()); - } - - public static boolean runPredicate(String rule, Map resolver, Context context) { - return runPredicate(rule, new MapVariableResolver(resolver), context); - } - - public static boolean runPredicate(String rule, VariableResolver resolver) { - return runPredicate(rule, resolver, Context.EMPTY_CONTEXT()); - } - - public static boolean runPredicate(String rule, VariableResolver resolver, Context context) { - StellarPredicateProcessor processor = new StellarPredicateProcessor(); - Assert.assertTrue(rule + " not valid.", processor.validate(rule)); - return processor.parse(rule, resolver, StellarFunctions.FUNCTION_RESOLVER(), context); - } - - public static void runWithArguments(String function, Object argument, Object expected) { - runWithArguments(function, ImmutableList.of(argument), expected); - } - - public static void runWithArguments(String function, List<Object> arguments, Object expected) { - Supplier<Stream<Map.Entry<String, Object>>> kvStream = () -> StreamSupport.stream(new XRange(arguments.size()), false) - .map( i -> new AbstractMap.SimpleImmutableEntry<>("var" + i, arguments.get(i))); - - String args = kvStream.get().map( kv -> kv.getKey()) - .collect(Collectors.joining(",")); - Map<String, Object> variables = kvStream.get().collect(Collectors.toMap(kv -> kv.getKey(), kv -> kv.getValue())); - String stellarStatement = function + "(" + args + ")"; - String reason = stellarStatement + " != " + expected + " with variables: " + variables; - - if(expected instanceof Double) { - Assert.assertEquals(reason, (Double)expected, (Double)run(stellarStatement, variables), 1e-6); - } - else { - Assert.assertEquals(reason, expected, run(stellarStatement, variables)); - } - } - - public static class XRange extends Spliterators.AbstractIntSpliterator { - int end; - int i = 0; - - public XRange(int start, int end) { - super(end - start, 0); - i = start; - this.end = end; - } - - public XRange(int end) { - this(0, end); - } - - @Override - public boolean tryAdvance(IntConsumer action) { - boolean isDone = i >= end; - if(isDone) { - return false; - } - else { - action.accept(i); - i++; - return true; - } - } - - /** - * {@inheritDoc} - * - * @param action - * @implSpec If the action is an instance of {@code IntConsumer} then it is cast - * to {@code IntConsumer} and passed to - * {@link #tryAdvance(IntConsumer)}; otherwise - * the action is adapted to an instance of {@code IntConsumer}, by - * boxing the argument of {@code IntConsumer}, and then passed to - * {@link #tryAdvance(IntConsumer)}. - */ - @Override - public boolean tryAdvance(Consumer<? super Integer> action) { - boolean isDone = i >= end; - if(isDone) { - return false; - } - else { - action.accept(i); - i++; - return true; - } - } - } - -} http://git-wip-us.apache.org/repos/asf/metron/blob/a5b13777/metron-platform/metron-data-management/src/main/java/org/apache/metron/dataloads/extractor/TransformFilterExtractorDecorator.java ---------------------------------------------------------------------- diff --git a/metron-platform/metron-data-management/src/main/java/org/apache/metron/dataloads/extractor/TransformFilterExtractorDecorator.java b/metron-platform/metron-data-management/src/main/java/org/apache/metron/dataloads/extractor/TransformFilterExtractorDecorator.java index a99db87..516c31e 100644 --- a/metron-platform/metron-data-management/src/main/java/org/apache/metron/dataloads/extractor/TransformFilterExtractorDecorator.java +++ b/metron-platform/metron-data-management/src/main/java/org/apache/metron/dataloads/extractor/TransformFilterExtractorDecorator.java @@ -22,12 +22,12 @@ import org.apache.commons.lang.StringUtils; import org.apache.curator.framework.CuratorFramework; import org.apache.log4j.Logger; import org.apache.metron.common.configuration.ConfigurationsUtils; -import org.apache.metron.common.dsl.Context; -import org.apache.metron.common.dsl.MapVariableResolver; -import org.apache.metron.common.dsl.StellarFunctions; -import org.apache.metron.common.stellar.StellarPredicateProcessor; -import org.apache.metron.common.stellar.StellarProcessor; -import org.apache.metron.common.utils.ConversionUtils; +import org.apache.metron.stellar.dsl.Context; +import org.apache.metron.stellar.dsl.MapVariableResolver; +import org.apache.metron.stellar.dsl.StellarFunctions; +import org.apache.metron.stellar.common.StellarPredicateProcessor; +import org.apache.metron.stellar.common.StellarProcessor; +import org.apache.metron.stellar.common.utils.ConversionUtils; import org.apache.metron.common.utils.JSONUtils; import org.apache.metron.enrichment.lookup.LookupKV; http://git-wip-us.apache.org/repos/asf/metron/blob/a5b13777/metron-platform/metron-data-management/src/main/java/org/apache/metron/dataloads/nonbulk/flatfile/LoadOptions.java ---------------------------------------------------------------------- diff --git a/metron-platform/metron-data-management/src/main/java/org/apache/metron/dataloads/nonbulk/flatfile/LoadOptions.java b/metron-platform/metron-data-management/src/main/java/org/apache/metron/dataloads/nonbulk/flatfile/LoadOptions.java index ddaf6a6..448f406 100644 --- a/metron-platform/metron-data-management/src/main/java/org/apache/metron/dataloads/nonbulk/flatfile/LoadOptions.java +++ b/metron-platform/metron-data-management/src/main/java/org/apache/metron/dataloads/nonbulk/flatfile/LoadOptions.java @@ -21,7 +21,7 @@ import com.google.common.base.Joiner; import com.google.common.base.Splitter; import org.apache.commons.cli.*; import org.apache.commons.io.FileUtils; -import org.apache.metron.common.utils.ConversionUtils; +import org.apache.metron.stellar.common.utils.ConversionUtils; import org.apache.metron.common.utils.cli.OptionHandler; import org.apache.metron.dataloads.nonbulk.flatfile.importer.ImportStrategy; http://git-wip-us.apache.org/repos/asf/metron/blob/a5b13777/metron-platform/metron-enrichment/src/main/java/org/apache/metron/enrichment/adapters/stellar/StellarAdapter.java ---------------------------------------------------------------------- diff --git a/metron-platform/metron-enrichment/src/main/java/org/apache/metron/enrichment/adapters/stellar/StellarAdapter.java b/metron-platform/metron-enrichment/src/main/java/org/apache/metron/enrichment/adapters/stellar/StellarAdapter.java index 4b78821..a218d51 100644 --- a/metron-platform/metron-enrichment/src/main/java/org/apache/metron/enrichment/adapters/stellar/StellarAdapter.java +++ b/metron-platform/metron-enrichment/src/main/java/org/apache/metron/enrichment/adapters/stellar/StellarAdapter.java @@ -19,12 +19,12 @@ package org.apache.metron.enrichment.adapters.stellar; import org.apache.metron.common.configuration.enrichment.SensorEnrichmentConfig; import org.apache.metron.common.configuration.enrichment.handler.ConfigHandler; -import org.apache.metron.common.dsl.Context; -import org.apache.metron.common.dsl.MapVariableResolver; -import org.apache.metron.common.dsl.StellarFunctions; -import org.apache.metron.common.dsl.VariableResolver; -import org.apache.metron.common.stellar.StellarProcessor; -import org.apache.metron.common.utils.ConversionUtils; +import org.apache.metron.stellar.dsl.Context; +import org.apache.metron.stellar.dsl.MapVariableResolver; +import org.apache.metron.stellar.dsl.StellarFunctions; +import org.apache.metron.stellar.dsl.VariableResolver; +import org.apache.metron.stellar.common.StellarProcessor; +import org.apache.metron.stellar.common.utils.ConversionUtils; import org.apache.metron.enrichment.bolt.CacheKey; import org.apache.metron.enrichment.interfaces.EnrichmentAdapter; import org.json.simple.JSONObject; http://git-wip-us.apache.org/repos/asf/metron/blob/a5b13777/metron-platform/metron-enrichment/src/main/java/org/apache/metron/enrichment/bolt/CacheKey.java ---------------------------------------------------------------------- diff --git a/metron-platform/metron-enrichment/src/main/java/org/apache/metron/enrichment/bolt/CacheKey.java b/metron-platform/metron-enrichment/src/main/java/org/apache/metron/enrichment/bolt/CacheKey.java index a3a92ac..b8e4d37 100644 --- a/metron-platform/metron-enrichment/src/main/java/org/apache/metron/enrichment/bolt/CacheKey.java +++ b/metron-platform/metron-enrichment/src/main/java/org/apache/metron/enrichment/bolt/CacheKey.java @@ -18,7 +18,7 @@ package org.apache.metron.enrichment.bolt; import org.apache.metron.common.configuration.enrichment.SensorEnrichmentConfig; -import org.apache.metron.common.utils.ConversionUtils; +import org.apache.metron.stellar.common.utils.ConversionUtils; public class CacheKey { private String field; http://git-wip-us.apache.org/repos/asf/metron/blob/a5b13777/metron-platform/metron-enrichment/src/main/java/org/apache/metron/enrichment/bolt/GenericEnrichmentBolt.java ---------------------------------------------------------------------- diff --git a/metron-platform/metron-enrichment/src/main/java/org/apache/metron/enrichment/bolt/GenericEnrichmentBolt.java b/metron-platform/metron-enrichment/src/main/java/org/apache/metron/enrichment/bolt/GenericEnrichmentBolt.java index d6f1304..8b6fee0 100644 --- a/metron-platform/metron-enrichment/src/main/java/org/apache/metron/enrichment/bolt/GenericEnrichmentBolt.java +++ b/metron-platform/metron-enrichment/src/main/java/org/apache/metron/enrichment/bolt/GenericEnrichmentBolt.java @@ -33,8 +33,8 @@ import org.apache.metron.common.Constants; import org.apache.metron.common.bolt.ConfiguredEnrichmentBolt; import org.apache.metron.common.configuration.ConfigurationType; import org.apache.metron.common.configuration.enrichment.SensorEnrichmentConfig; -import org.apache.metron.common.dsl.Context; -import org.apache.metron.common.dsl.StellarFunctions; +import org.apache.metron.stellar.dsl.Context; +import org.apache.metron.stellar.dsl.StellarFunctions; import org.apache.metron.common.utils.ErrorUtils; import org.apache.metron.enrichment.configuration.Enrichment; import org.apache.metron.enrichment.interfaces.EnrichmentAdapter; @@ -44,7 +44,6 @@ import org.slf4j.LoggerFactory; import java.util.HashSet; import java.util.Map; -import java.util.Optional; import java.util.concurrent.TimeUnit; /** http://git-wip-us.apache.org/repos/asf/metron/blob/a5b13777/metron-platform/metron-enrichment/src/main/java/org/apache/metron/enrichment/bolt/ThreatIntelJoinBolt.java ---------------------------------------------------------------------- diff --git a/metron-platform/metron-enrichment/src/main/java/org/apache/metron/enrichment/bolt/ThreatIntelJoinBolt.java b/metron-platform/metron-enrichment/src/main/java/org/apache/metron/enrichment/bolt/ThreatIntelJoinBolt.java index d4865e2..ee0323d 100644 --- a/metron-platform/metron-enrichment/src/main/java/org/apache/metron/enrichment/bolt/ThreatIntelJoinBolt.java +++ b/metron-platform/metron-enrichment/src/main/java/org/apache/metron/enrichment/bolt/ThreatIntelJoinBolt.java @@ -24,13 +24,13 @@ import org.apache.metron.common.configuration.enrichment.handler.ConfigHandler; import org.apache.metron.common.configuration.enrichment.threatintel.RuleScore; import org.apache.metron.common.configuration.enrichment.threatintel.ThreatScore; import org.apache.metron.common.configuration.enrichment.threatintel.ThreatTriageConfig; -import org.apache.metron.common.dsl.Context; -import org.apache.metron.common.dsl.StellarFunctions; -import org.apache.metron.common.dsl.functions.resolver.FunctionResolver; import org.apache.metron.common.message.MessageGetStrategy; -import org.apache.metron.common.utils.ConversionUtils; import org.apache.metron.common.utils.MessageUtils; import org.apache.metron.enrichment.adapters.geo.GeoLiteDatabase; +import org.apache.metron.stellar.dsl.Context; +import org.apache.metron.stellar.dsl.StellarFunctions; +import org.apache.metron.stellar.dsl.functions.resolver.FunctionResolver; +import org.apache.metron.stellar.common.utils.ConversionUtils; import org.apache.metron.threatintel.triage.ThreatTriageProcessor; import org.apache.storm.task.TopologyContext; import org.apache.storm.tuple.Tuple; http://git-wip-us.apache.org/repos/asf/metron/blob/a5b13777/metron-platform/metron-enrichment/src/main/java/org/apache/metron/enrichment/lookup/accesstracker/BloomAccessTracker.java ---------------------------------------------------------------------- diff --git a/metron-platform/metron-enrichment/src/main/java/org/apache/metron/enrichment/lookup/accesstracker/BloomAccessTracker.java b/metron-platform/metron-enrichment/src/main/java/org/apache/metron/enrichment/lookup/accesstracker/BloomAccessTracker.java index 3b7e437..d21638d 100644 --- a/metron-platform/metron-enrichment/src/main/java/org/apache/metron/enrichment/lookup/accesstracker/BloomAccessTracker.java +++ b/metron-platform/metron-enrichment/src/main/java/org/apache/metron/enrichment/lookup/accesstracker/BloomAccessTracker.java @@ -17,7 +17,7 @@ */ package org.apache.metron.enrichment.lookup.accesstracker; -import org.apache.metron.common.utils.BloomFilter; +import org.apache.metron.stellar.common.utils.BloomFilter; import org.apache.metron.enrichment.lookup.LookupKey; import java.io.*; http://git-wip-us.apache.org/repos/asf/metron/blob/a5b13777/metron-platform/metron-enrichment/src/main/java/org/apache/metron/enrichment/lookup/accesstracker/PersistentBloomTrackerCreator.java ---------------------------------------------------------------------- diff --git a/metron-platform/metron-enrichment/src/main/java/org/apache/metron/enrichment/lookup/accesstracker/PersistentBloomTrackerCreator.java b/metron-platform/metron-enrichment/src/main/java/org/apache/metron/enrichment/lookup/accesstracker/PersistentBloomTrackerCreator.java index 02d0c7f..a7b1b5f 100644 --- a/metron-platform/metron-enrichment/src/main/java/org/apache/metron/enrichment/lookup/accesstracker/PersistentBloomTrackerCreator.java +++ b/metron-platform/metron-enrichment/src/main/java/org/apache/metron/enrichment/lookup/accesstracker/PersistentBloomTrackerCreator.java @@ -19,7 +19,7 @@ package org.apache.metron.enrichment.lookup.accesstracker; import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.hbase.HBaseConfiguration; -import org.apache.metron.common.utils.ConversionUtils; +import org.apache.metron.stellar.common.utils.ConversionUtils; import org.apache.metron.hbase.TableProvider; import java.io.IOException; http://git-wip-us.apache.org/repos/asf/metron/blob/a5b13777/metron-platform/metron-enrichment/src/main/java/org/apache/metron/enrichment/stellar/GeoEnrichmentFunctions.java ---------------------------------------------------------------------- diff --git a/metron-platform/metron-enrichment/src/main/java/org/apache/metron/enrichment/stellar/GeoEnrichmentFunctions.java b/metron-platform/metron-enrichment/src/main/java/org/apache/metron/enrichment/stellar/GeoEnrichmentFunctions.java index 42913b2..0dea61c 100644 --- a/metron-platform/metron-enrichment/src/main/java/org/apache/metron/enrichment/stellar/GeoEnrichmentFunctions.java +++ b/metron-platform/metron-enrichment/src/main/java/org/apache/metron/enrichment/stellar/GeoEnrichmentFunctions.java @@ -18,10 +18,10 @@ package org.apache.metron.enrichment.stellar; import org.apache.log4j.Logger; -import org.apache.metron.common.dsl.Context; -import org.apache.metron.common.dsl.ParseException; -import org.apache.metron.common.dsl.Stellar; -import org.apache.metron.common.dsl.StellarFunction; +import org.apache.metron.stellar.dsl.Context; +import org.apache.metron.stellar.dsl.ParseException; +import org.apache.metron.stellar.dsl.Stellar; +import org.apache.metron.stellar.dsl.StellarFunction; import org.apache.metron.enrichment.adapters.geo.GeoLiteDatabase; import java.util.HashMap; http://git-wip-us.apache.org/repos/asf/metron/blob/a5b13777/metron-platform/metron-enrichment/src/main/java/org/apache/metron/enrichment/stellar/SimpleHBaseEnrichmentFunctions.java ---------------------------------------------------------------------- diff --git a/metron-platform/metron-enrichment/src/main/java/org/apache/metron/enrichment/stellar/SimpleHBaseEnrichmentFunctions.java b/metron-platform/metron-enrichment/src/main/java/org/apache/metron/enrichment/stellar/SimpleHBaseEnrichmentFunctions.java index d2454fe..e05f28d 100644 --- a/metron-platform/metron-enrichment/src/main/java/org/apache/metron/enrichment/stellar/SimpleHBaseEnrichmentFunctions.java +++ b/metron-platform/metron-enrichment/src/main/java/org/apache/metron/enrichment/stellar/SimpleHBaseEnrichmentFunctions.java @@ -19,14 +19,13 @@ package org.apache.metron.enrichment.stellar; import com.google.common.cache.Cache; import com.google.common.cache.CacheBuilder; -import com.google.common.cache.CacheLoader; import org.apache.hadoop.hbase.HBaseConfiguration; import org.apache.hadoop.hbase.client.HTableInterface; import org.apache.log4j.Logger; -import org.apache.metron.common.dsl.Context; -import org.apache.metron.common.dsl.ParseException; -import org.apache.metron.common.dsl.Stellar; -import org.apache.metron.common.dsl.StellarFunction; +import org.apache.metron.stellar.dsl.Context; +import org.apache.metron.stellar.dsl.ParseException; +import org.apache.metron.stellar.dsl.Stellar; +import org.apache.metron.stellar.dsl.StellarFunction; import org.apache.metron.enrichment.converter.EnrichmentKey; import org.apache.metron.enrichment.converter.EnrichmentValue; import org.apache.metron.enrichment.lookup.EnrichmentLookup; http://git-wip-us.apache.org/repos/asf/metron/blob/a5b13777/metron-platform/metron-enrichment/src/main/java/org/apache/metron/enrichment/writer/SimpleHbaseEnrichmentWriter.java ---------------------------------------------------------------------- diff --git a/metron-platform/metron-enrichment/src/main/java/org/apache/metron/enrichment/writer/SimpleHbaseEnrichmentWriter.java b/metron-platform/metron-enrichment/src/main/java/org/apache/metron/enrichment/writer/SimpleHbaseEnrichmentWriter.java index 83c7151..e637156 100644 --- a/metron-platform/metron-enrichment/src/main/java/org/apache/metron/enrichment/writer/SimpleHbaseEnrichmentWriter.java +++ b/metron-platform/metron-enrichment/src/main/java/org/apache/metron/enrichment/writer/SimpleHbaseEnrichmentWriter.java @@ -28,7 +28,7 @@ import org.apache.hadoop.hbase.client.HTableInterface; import org.apache.hadoop.hbase.client.Put; import org.apache.metron.common.configuration.writer.WriterConfiguration; import org.apache.metron.common.writer.BulkMessageWriter; -import org.apache.metron.common.utils.ConversionUtils; +import org.apache.metron.stellar.common.utils.ConversionUtils; import org.apache.metron.common.utils.ReflectionUtils; import org.apache.metron.enrichment.converter.EnrichmentConverter; import org.apache.metron.enrichment.converter.EnrichmentKey; http://git-wip-us.apache.org/repos/asf/metron/blob/a5b13777/metron-platform/metron-enrichment/src/main/java/org/apache/metron/threatintel/triage/ThreatTriageProcessor.java ---------------------------------------------------------------------- diff --git a/metron-platform/metron-enrichment/src/main/java/org/apache/metron/threatintel/triage/ThreatTriageProcessor.java b/metron-platform/metron-enrichment/src/main/java/org/apache/metron/threatintel/triage/ThreatTriageProcessor.java index 8b09e85..cb11a27 100644 --- a/metron-platform/metron-enrichment/src/main/java/org/apache/metron/threatintel/triage/ThreatTriageProcessor.java +++ b/metron-platform/metron-enrichment/src/main/java/org/apache/metron/threatintel/triage/ThreatTriageProcessor.java @@ -26,13 +26,13 @@ import org.apache.metron.common.configuration.enrichment.threatintel.RuleScore; import org.apache.metron.common.configuration.enrichment.threatintel.ThreatIntelConfig; import org.apache.metron.common.configuration.enrichment.threatintel.ThreatScore; import org.apache.metron.common.configuration.enrichment.threatintel.ThreatTriageConfig; -import org.apache.metron.common.dsl.Context; -import org.apache.metron.common.dsl.MapVariableResolver; -import org.apache.metron.common.dsl.VariableResolver; -import org.apache.metron.common.dsl.functions.resolver.FunctionResolver; -import org.apache.metron.common.stellar.StellarPredicateProcessor; -import org.apache.metron.common.stellar.StellarProcessor; -import org.apache.metron.common.utils.ConversionUtils; +import org.apache.metron.stellar.dsl.Context; +import org.apache.metron.stellar.dsl.MapVariableResolver; +import org.apache.metron.stellar.dsl.VariableResolver; +import org.apache.metron.stellar.dsl.functions.resolver.FunctionResolver; +import org.apache.metron.stellar.common.StellarPredicateProcessor; +import org.apache.metron.stellar.common.StellarProcessor; +import org.apache.metron.stellar.common.utils.ConversionUtils; import javax.annotation.Nullable; import java.util.List;
