Skip to content

Commit

Permalink
surefire update
Browse files Browse the repository at this point in the history
  • Loading branch information
stas-panasiuk committed Feb 12, 2024
1 parent 110ac10 commit c947125
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 50 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,30 +19,19 @@
package org.apache.metron.stellar.common.utils;

import com.google.common.collect.ImmutableList;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.util.AbstractMap;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Spliterators;
import org.apache.commons.lang3.exception.ExceptionUtils;
import org.apache.metron.stellar.common.StellarPredicateProcessor;
import org.apache.metron.stellar.common.StellarProcessor;
import org.apache.metron.stellar.dsl.*;

import java.io.*;
import java.util.*;
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;
import org.apache.commons.lang3.exception.ExceptionUtils;
import org.apache.metron.stellar.common.StellarPredicateProcessor;
import org.apache.metron.stellar.common.StellarProcessor;
import org.apache.metron.stellar.dsl.Context;
import org.apache.metron.stellar.dsl.DefaultVariableResolver;
import org.apache.metron.stellar.dsl.MapVariableResolver;
import org.apache.metron.stellar.dsl.StellarFunctions;
import org.apache.metron.stellar.dsl.VariableResolver;

/**
* Utilities for executing and validating Stellar expressions.
Expand Down Expand Up @@ -223,7 +212,6 @@ public static Object run(String expression, VariableResolver variables) {
* @return The result of executing the expression.
*/
public static Object run(String expression, Context context) {
System.out.println("TESTING: " + expression + ", context: " + context);
return run(expression, Collections.emptyMap(), context);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import org.junit.jupiter.migrationsupport.rules.EnableRuleMigrationSupport;
import org.junit.rules.TemporaryFolder;
import org.mockserver.integration.ClientAndServer;
import org.slf4j.LoggerFactory;

import java.io.File;
import java.nio.charset.StandardCharsets;
Expand All @@ -51,6 +52,8 @@ public class RestFunctionsIntegrationTest {
@Rule
public TemporaryFolder tempDir = new TemporaryFolder();

private static final org.slf4j.Logger LOG = LoggerFactory.getLogger(RestFunctionsIntegrationTest.class);

private static final int MOCK_PROXY_PORT = 1080;

// Use plain Java API, because we can't use the @Rule and the JUnit5 extension isn't released.
Expand All @@ -70,9 +73,9 @@ public class RestFunctionsIntegrationTest {

@BeforeEach
public void setup() throws Exception {
System.out.println("TESTING Setting up....");
LOG.error("TESTING Setting up....");
mockServerClient = startClientAndServer(MOCK_PROXY_PORT);
System.out.println("TESTING MOCK_PROXY_PORT: " + MOCK_PROXY_PORT);
LOG.error("TESTING MOCK_PROXY_PORT: " + MOCK_PROXY_PORT);

context = new Context.Builder()
.with(Context.Capabilities.GLOBAL_CONFIG, HashMap::new)
Expand All @@ -85,17 +88,17 @@ public void setup() throws Exception {
FileUtils.writeStringToFile(proxyBasicAuthPasswordFile, proxyAuthPassword, StandardCharsets.UTF_8);

// By default, the mock server expects a GET request with the path set to /get
System.out.println("TESTING MOCK_PROXY_PORT: " + MOCK_PROXY_PORT);
LOG.error("TESTING MOCK_PROXY_PORT: " + MOCK_PROXY_PORT);
baseUri = String.format("http://localhost:%d", MOCK_PROXY_PORT);
System.out.println("TESTING baseUri: " + baseUri);
LOG.error("TESTING baseUri: " + baseUri);
getUri = baseUri + "/get";
System.out.println("TESTING getUri: " + getUri);
LOG.error("TESTING getUri: " + getUri);
emptyGetUri = baseUri + "/get/empty";
System.out.println("TESTING emptyGetUri: " + emptyGetUri);
LOG.error("TESTING emptyGetUri: " + emptyGetUri);
postUri = baseUri + "/post";
System.out.println("TESTING postUri: " + postUri);
LOG.error("TESTING postUri: " + postUri);
emptyPostUri = baseUri + "/post/empty";
System.out.println("TESTING emptyPostUri: " + emptyPostUri);
LOG.error("TESTING emptyPostUri: " + emptyPostUri);
mockServerClient.when(
request()
.withMethod("GET")
Expand Down Expand Up @@ -135,7 +138,7 @@ public void teardown() {
@Test
@SuppressWarnings("unchecked")
public void restGetShouldSucceed() {
System.out.printf("TESTING[restGetShouldSucceed] getUri: [%s]%n", getUri);
LOG.error("TESTING[restGetShouldSucceed] getUri: [{}]", getUri);
Map<String, Object> actual = (Map<String, Object>) run(String.format("REST_GET('%s')", getUri), context);

assertEquals(1, actual.size());
Expand All @@ -157,7 +160,7 @@ public void restGetShouldSucceedWithQueryParameters() {
.withBody("{\"get.with.query.parameters\":\"success\"}"));

Map<String, Object> variables = ImmutableMap.of("queryParameters", ImmutableMap.of("key", "value"));
System.out.printf("TESTING[restGetShouldSucceedWithQueryParameters] baseUri: [%s], variables: [%s]%n", baseUri, variables);
LOG.error("TESTING[restGetShouldSucceedWithQueryParameters] baseUri: [{}], variables: [{}]", baseUri, variables);
Map<String, Object> actual = (Map<String, Object>) run(String.format("REST_GET('%s', {}, queryParameters)",
baseUri + "/get/with/query/parameters"), variables, context);

Expand All @@ -183,7 +186,7 @@ public void restGetShouldSucceedWithProxy() {
put(PROXY_PORT, MOCK_PROXY_PORT);
}});

System.out.printf("TESTING[restGetShouldSucceedWithProxy] getUri: [%s]%n", getUri);
LOG.error("TESTING[restGetShouldSucceedWithProxy] getUri: [{}]", getUri);
Map<String, Object> actual = (Map<String, Object>) run(String.format("REST_GET('%s')", getUri), context);

assertEquals(1, actual.size());
Expand All @@ -202,7 +205,7 @@ public void restGetShouldHandleErrorStatusCode() {
.respond(response()
.withStatusCode(403));

System.out.printf("TESTING[restGetShouldHandleErrorStatusCode] getUri: [%s]%n", getUri);
LOG.error("TESTING[restGetShouldHandleErrorStatusCode] getUri: [{}]", getUri);
assertNull(run(String.format("REST_GET('%s')", getUri), context));
}

Expand All @@ -220,7 +223,7 @@ public void restGetShouldHandleErrorStatusCode() {
*/
@Test
public void restGetShouldReturnEmptyContentOverride() {
System.out.printf("TESTING[restGetShouldReturnEmptyContentOverride] emptyGetUri: [%s], emptyContentOverride: [%s]%n", emptyGetUri, emptyContentOverride);
LOG.error("TESTING[restGetShouldReturnEmptyContentOverride] emptyGetUri: [{}], emptyContentOverride: [{}]", emptyGetUri, emptyContentOverride);
assertEquals("function config override", run(String.format("REST_GET('%s', %s)", emptyGetUri, emptyContentOverride), context));
}

Expand All @@ -244,7 +247,7 @@ public void restGetShouldReturnErrorValueOverride() {
.respond(response()
.withStatusCode(500));

System.out.printf("TESTING[restGetShouldReturnErrorValueOverride] getUri: [%s], errorValueOverride: [%s]%n", getUri, errorValueOverride);
LOG.error("TESTING[restGetShouldReturnErrorValueOverride] getUri: [{}], errorValueOverride: [{}]", getUri, errorValueOverride);
Object result = run(String.format("REST_GET('%s', %s)", getUri, errorValueOverride), context);
assertEquals("error message" , result);
}
Expand Down Expand Up @@ -273,7 +276,7 @@ public void restGetShouldTimeout() {

context.addCapability(Context.Capabilities.GLOBAL_CONFIG, () -> globalConfig);

System.out.printf("TESTING[restGetShouldTimeout] uri: [%s]%n", uri);
LOG.error("TESTING[restGetShouldTimeout] uri: [{}]", uri);
Map<String, Object> actual = (Map<String, Object>) run(String.format("REST_GET('%s')", uri), context);
assertNull(actual);
}
Expand Down Expand Up @@ -302,7 +305,7 @@ public void restGetShouldTimeoutWithSuppliedTimeout() {
.withBody("{\"get\":\"success\"}"));

String expression = String.format("REST_GET('%s', %s)", uri, timeoutConfig);
System.out.printf("TESTING[restGetShouldTimeoutWithSuppliedTimeout] expression: [%s]%n", expression);
LOG.error("TESTING[restGetShouldTimeoutWithSuppliedTimeout] expression: [{}]", expression);
Map<String, Object> actual = (Map<String, Object>) run(expression, context);
assertNull(actual);
}
Expand All @@ -312,7 +315,7 @@ public void restGetShouldTimeoutWithSuppliedTimeout() {
*/
@Test
public void restGetShouldHandleURISyntaxException() {
System.out.printf("TESTING[restGetShouldHandleURISyntaxException]%n");
LOG.error("TESTING[restGetShouldHandleURISyntaxException]");
ParseException e = assertThrows(ParseException.class, () -> run("REST_GET('some invalid uri')", context));
assertEquals("Unable to parse REST_GET('some invalid uri'): Unable to parse: REST_GET('some invalid uri') due to: Illegal character in path at index 4: some invalid uri", e.getMessage());
}
Expand All @@ -324,7 +327,7 @@ public void restGetShouldHandleURISyntaxException() {
*/
@Test
public void restGetShouldThrownExceptionOnMissingParameter() {
System.out.printf("TESTING[restGetShouldThrownExceptionOnMissingParameter]%n");
LOG.error("TESTING[restGetShouldThrownExceptionOnMissingParameter]");
ParseException e = assertThrows(ParseException.class, () -> run("REST_GET()", context));
assertEquals("Unable to parse REST_GET(): Unable to parse: REST_GET() due to: Expected at least 1 argument(s), found 0", e.getMessage());
}
Expand All @@ -342,7 +345,7 @@ public void restGetShouldUseGlobalConfig() {
}};
context.addCapability(Context.Capabilities.GLOBAL_CONFIG, () -> globalConfig);

System.out.printf("TESTING[restGetShouldUseGlobalConfig] emptyGetUri: [%s]%n", emptyGetUri);
LOG.error("TESTING[restGetShouldUseGlobalConfig] emptyGetUri: [{}]", emptyGetUri);
assertEquals("global config override", run(String.format("REST_GET('%s')", emptyGetUri), context));
}

Expand All @@ -362,7 +365,7 @@ public void restGetShouldUseGetConfig() {
}};
context.addCapability(Context.Capabilities.GLOBAL_CONFIG, () -> globalConfig);

System.out.printf("TESTING[restGetShouldUseGetConfig] emptyGetUri: [%s]%n", emptyGetUri);
LOG.error("TESTING[restGetShouldUseGetConfig] emptyGetUri: [{}]", emptyGetUri);
assertEquals("get config override", run(String.format("REST_GET('%s')", emptyGetUri), context));
}

Expand All @@ -382,7 +385,7 @@ public void restGetShouldUseFunctionConfig() {
}};
context.addCapability(Context.Capabilities.GLOBAL_CONFIG, () -> globalConfig);

System.out.printf("TESTING[restGetShouldUseFunctionConfig] emptyGetUri: [%s], emptyContentOverride: [%s]%n", emptyGetUri, emptyContentOverride);
LOG.error("TESTING[restGetShouldUseFunctionConfig] emptyGetUri: [{}], emptyContentOverride: [{}]", emptyGetUri, emptyContentOverride);
assertEquals("function config override", run(String.format("REST_GET('%s', %s)", emptyGetUri, emptyContentOverride), context));
}

Expand All @@ -392,7 +395,7 @@ public void restGetShouldUseFunctionConfig() {
@Test
@SuppressWarnings("unchecked")
public void restPostShouldSucceed() {
System.out.printf("TESTING[restPostShouldSucceed] postUri: [%s]%n", postUri);
LOG.error("TESTING[restPostShouldSucceed] postUri: [{}]", postUri);
Map<String, Object> actual = (Map<String, Object>) run(String.format("REST_POST('%s', '{\"key\":\"value\"}')", postUri), context);

assertEquals(1, actual.size());
Expand All @@ -414,7 +417,7 @@ public void restPostShouldSucceedWithQueryParameters() {
.withBody("{\"post.with.query.parameters\":\"success\"}"));

Map<String, Object> variables = ImmutableMap.of("queryParameters", ImmutableMap.of("key", "value"));
System.out.printf("TESTING[restPostShouldSucceedWithQueryParameters] baseUri: [%s], variables: [%s]%n", baseUri,variables);
LOG.error("TESTING[restPostShouldSucceedWithQueryParameters] baseUri: [{}], variables: [{}]", baseUri,variables);
Map<String, Object> actual = (Map<String, Object>) run(String.format("REST_POST('%s', {}, {}, queryParameters)",
baseUri + "/post/with/query/parameters"), variables, context);

Expand All @@ -429,7 +432,7 @@ public void restPostShouldSucceedWithQueryParameters() {
@SuppressWarnings("unchecked")
public void restPostShouldSucceedWithStellarMap() {
Map<String, Object> variables = ImmutableMap.of("body", ImmutableMap.of("key", "value"));
System.out.printf("TESTING[restPostShouldSucceedWithStellarMap] postUri: [%s], variables: [%s]%n", postUri,variables);
LOG.error("TESTING[restPostShouldSucceedWithStellarMap] postUri: [{}], variables: [{}]", postUri,variables);
Map<String, Object> actual = (Map<String, Object>) run(String.format("REST_POST('%s', body)", postUri), variables, context);

assertEquals(1, actual.size());
Expand All @@ -441,7 +444,7 @@ public void restPostShouldSucceedWithStellarMap() {
*/
@Test
public void restPostShouldHandleURISyntaxException() {
System.out.printf("TESTING[restPostShouldHandleURISyntaxException]%n");
LOG.error("TESTING[restPostShouldHandleURISyntaxException]");
ParseException e = assertThrows(ParseException.class, () -> run("REST_POST('some invalid uri', {})", context));
assertEquals("Unable to parse REST_POST('some invalid uri', {}): Unable to parse: REST_POST('some invalid uri', {}) due to: Illegal character in path at index 4: some invalid uri", e.getMessage());
}
Expand All @@ -451,7 +454,7 @@ public void restPostShouldHandleURISyntaxException() {
*/
@Test
public void restPostShouldThrowExceptionOnMalformedJson() {
System.out.printf("TESTING[restPostShouldThrowExceptionOnMalformedJson] postUri: [%s]%n", postUri);
LOG.error("TESTING[restPostShouldThrowExceptionOnMalformedJson] postUri: [{}]", postUri);
ParseException e = assertThrows(ParseException.class, () -> run(String.format("REST_POST('%s', 'malformed json')", postUri), context));
assertEquals(
String.format(
Expand All @@ -475,7 +478,7 @@ public void restPostShouldUseGlobalConfig() {
}};
context.addCapability(Context.Capabilities.GLOBAL_CONFIG, () -> globalConfig);

System.out.printf("TESTING[restPostShouldUseGlobalConfig] emptyGetUri: [%s]%n", emptyGetUri);
LOG.error("TESTING[restPostShouldUseGlobalConfig] emptyGetUri: [{}]", emptyGetUri);
assertEquals("global config override", run(String.format("REST_POST('%s', {})", emptyGetUri), context));
}

Expand All @@ -495,7 +498,7 @@ public void restPostShouldUseGetConfig() {
}};
context.addCapability(Context.Capabilities.GLOBAL_CONFIG, () -> globalConfig);

System.out.printf("TESTING[restPostShouldUseGetConfig] emptyGetUri: [%s]%n", emptyGetUri);
LOG.error("TESTING[restPostShouldUseGetConfig] emptyGetUri: [{}]", emptyGetUri);
assertEquals("post config override", run(String.format("REST_POST('%s', {})", emptyGetUri), context));
}

Expand All @@ -515,7 +518,7 @@ public void restPostShouldUseFunctionConfig() {
}};
context.addCapability(Context.Capabilities.GLOBAL_CONFIG, () -> globalConfig);

System.out.printf("TESTING[restPostShouldUseFunctionConfig] emptyGetUri: [%s], emptyContentOverride: [%s]%n", emptyGetUri, emptyContentOverride);
LOG.error("TESTING[restPostShouldUseFunctionConfig] emptyGetUri: [{}], emptyContentOverride: [{}]", emptyGetUri, emptyContentOverride);
assertEquals("function config override", run(String.format("REST_POST('%s', {}, %s)", emptyGetUri, emptyContentOverride), context));
}

Expand Down
4 changes: 2 additions & 2 deletions flink-cyber/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,8 @@
<multiline-string.version>0.1.2</multiline-string.version>
<testcontainers.version>1.15.0</testcontainers.version>
<maven-shade-plugin.version>3.2.4</maven-shade-plugin.version>
<maven-failsafe-plugin.version>3.0.0-M5</maven-failsafe-plugin.version>
<maven-surefire-plugin.version>3.0.0-M5</maven-surefire-plugin.version>
<maven-failsafe-plugin.version>3.2.5</maven-failsafe-plugin.version>
<maven-surefire-plugin.version>3.2.5</maven-surefire-plugin.version>
<maven-resources-plugin.version>3.3.1</maven-resources-plugin.version>
<solr.version>8.4.1.${cdh.version}</solr.version>
<maxmind.version>2.13.1</maxmind.version>
Expand Down

0 comments on commit c947125

Please sign in to comment.