-
Notifications
You must be signed in to change notification settings - Fork 107
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into changelog-2.10.0
- Loading branch information
Showing
6 changed files
with
353 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<parent> | ||
<groupId>com.walmartlabs.concord.plugins.basic</groupId> | ||
<artifactId>parent</artifactId> | ||
<version>1.101.1-SNAPSHOT</version> | ||
<relativePath>../../pom.xml</relativePath> | ||
</parent> | ||
|
||
<artifactId>mock-tasks</artifactId> | ||
<packaging>takari-jar</packaging> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>com.walmartlabs.concord</groupId> | ||
<artifactId>concord-common</artifactId> | ||
<scope>provided</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>com.walmartlabs.concord</groupId> | ||
<artifactId>concord-sdk</artifactId> | ||
<scope>provided</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>com.walmartlabs.concord.runtime.v2</groupId> | ||
<artifactId>concord-runtime-sdk-v2</artifactId> | ||
<scope>provided</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>javax.inject</groupId> | ||
<artifactId>javax.inject</artifactId> | ||
<scope>provided</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>com.google.inject</groupId> | ||
<artifactId>guice</artifactId> | ||
<scope>provided</scope> | ||
</dependency> | ||
|
||
<!-- Immutables --> | ||
<dependency> | ||
<groupId>org.immutables</groupId> | ||
<artifactId>value</artifactId> | ||
<scope>provided</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.immutables</groupId> | ||
<artifactId>builder</artifactId> | ||
<scope>provided</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>com.google.code.findbugs</groupId> | ||
<artifactId>jsr305</artifactId> | ||
<scope>provided</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>com.google.errorprone</groupId> | ||
<artifactId>error_prone_annotations</artifactId> | ||
<scope>provided</scope> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.eclipse.sisu</groupId> | ||
<artifactId>org.eclipse.sisu.inject</artifactId> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>com.fasterxml.jackson.core</groupId> | ||
<artifactId>jackson-annotations</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>com.fasterxml.jackson.core</groupId> | ||
<artifactId>jackson-databind</artifactId> | ||
</dependency> | ||
</dependencies> | ||
|
||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.eclipse.sisu</groupId> | ||
<artifactId>sisu-maven-plugin</artifactId> | ||
</plugin> | ||
|
||
<plugin> | ||
<groupId>io.takari.maven.plugins</groupId> | ||
<artifactId>takari-lifecycle-plugin</artifactId> | ||
<configuration> | ||
<proc>proc</proc> | ||
</configuration> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
</project> |
58 changes: 58 additions & 0 deletions
58
plugins/tasks/mock/src/main/java/com/walmartlabs/concord/plugins/mock/MockDefinition.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
package com.walmartlabs.concord.plugins.mock; | ||
|
||
/*- | ||
* ***** | ||
* Concord | ||
* ----- | ||
* Copyright (C) 2017 - 2023 Walmart Inc. | ||
* ----- | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
* ===== | ||
*/ | ||
|
||
import com.fasterxml.jackson.databind.annotation.JsonDeserialize; | ||
import com.fasterxml.jackson.databind.annotation.JsonSerialize; | ||
import org.immutables.value.Value; | ||
|
||
import java.util.Collections; | ||
import java.util.Map; | ||
|
||
/** | ||
mocks: | ||
- name: "http" | ||
in: | ||
url: ".*" | ||
method: "POST" | ||
out: | ||
ok: true | ||
statusCode: 200 | ||
*/ | ||
|
||
@Value.Immutable | ||
@Value.Style(jdkOnly = true) | ||
@JsonSerialize(as = ImmutableMockDefinition.class) | ||
@JsonDeserialize(as = ImmutableMockDefinition.class) | ||
public interface MockDefinition { | ||
|
||
String name(); | ||
|
||
@Value.Default | ||
default Map<String, Object> in() { | ||
return Collections.emptyMap(); | ||
} | ||
|
||
@Value.Default | ||
default Map<String, Object> out() { | ||
return Collections.emptyMap(); | ||
} | ||
} |
53 changes: 53 additions & 0 deletions
53
...tasks/mock/src/main/java/com/walmartlabs/concord/plugins/mock/MockDefinitionProvider.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package com.walmartlabs.concord.plugins.mock; | ||
|
||
/*- | ||
* ***** | ||
* Concord | ||
* ----- | ||
* Copyright (C) 2017 - 2023 Walmart Inc. | ||
* ----- | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
* ===== | ||
*/ | ||
|
||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import com.walmartlabs.concord.runtime.v2.sdk.Context; | ||
import com.walmartlabs.concord.sdk.MapUtils; | ||
|
||
import javax.inject.Inject; | ||
import javax.inject.Singleton; | ||
import java.util.Collections; | ||
import java.util.Iterator; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
@Singleton | ||
public class MockDefinitionProvider { | ||
|
||
@Inject | ||
public MockDefinitionProvider() { | ||
} | ||
|
||
public synchronized MockDefinition get(Context ctx, String taskName) { | ||
List<Map<String, Object>> mocks = ctx.variables().getList("mocks", Collections.emptyList()); | ||
for (Iterator<Map<String, Object>> iterator = mocks.iterator(); iterator.hasNext(); ) { | ||
Map<String, Object> mock = iterator.next(); | ||
String name = MapUtils.assertString(mock, "name"); | ||
if (name.equals(taskName)) { | ||
iterator.remove(); | ||
return new ObjectMapper().convertValue(mock, MockDefinition.class); | ||
} | ||
} | ||
return null; | ||
} | ||
} |
37 changes: 37 additions & 0 deletions
37
plugins/tasks/mock/src/main/java/com/walmartlabs/concord/plugins/mock/MockModule.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package com.walmartlabs.concord.plugins.mock; | ||
|
||
/*- | ||
* ***** | ||
* Concord | ||
* ----- | ||
* Copyright (C) 2017 - 2023 Walmart Inc. | ||
* ----- | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
* ===== | ||
*/ | ||
|
||
import com.google.inject.Binder; | ||
import com.google.inject.multibindings.Multibinder; | ||
import com.walmartlabs.concord.runtime.v2.sdk.TaskProvider; | ||
|
||
import javax.inject.Named; | ||
|
||
@Named | ||
public class MockModule implements com.google.inject.Module { | ||
|
||
@Override | ||
public void configure(Binder binder) { | ||
Multibinder<TaskProvider> taskProviders = Multibinder.newSetBinder(binder, TaskProvider.class); | ||
taskProviders.addBinding().to(MockTaskProvider.class); | ||
} | ||
} |
48 changes: 48 additions & 0 deletions
48
plugins/tasks/mock/src/main/java/com/walmartlabs/concord/plugins/mock/MockTask.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package com.walmartlabs.concord.plugins.mock; | ||
|
||
/*- | ||
* ***** | ||
* Concord | ||
* ----- | ||
* Copyright (C) 2017 - 2023 Walmart Inc. | ||
* ----- | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
* ===== | ||
*/ | ||
|
||
import com.walmartlabs.concord.common.Matcher; | ||
import com.walmartlabs.concord.runtime.v2.sdk.Task; | ||
import com.walmartlabs.concord.runtime.v2.sdk.TaskResult; | ||
import com.walmartlabs.concord.runtime.v2.sdk.UserDefinedException; | ||
import com.walmartlabs.concord.runtime.v2.sdk.Variables; | ||
import com.walmartlabs.concord.sdk.MapUtils; | ||
|
||
public class MockTask implements Task { | ||
|
||
private final MockDefinition mockDefinition; | ||
|
||
public MockTask(MockDefinition mockDefinition) { | ||
this.mockDefinition = mockDefinition; | ||
} | ||
|
||
@Override | ||
public TaskResult execute(Variables input) { | ||
if (!Matcher.matches(input.toMap(), mockDefinition.in())) { | ||
throw new UserDefinedException("Input variables for '" + mockDefinition.name() + "' not matched with actual input params: " + input.toMap()); | ||
} | ||
|
||
boolean success = MapUtils.getBoolean(mockDefinition.out(), "ok", true); | ||
return TaskResult.of(success) | ||
.values(mockDefinition.out()); | ||
} | ||
} |
62 changes: 62 additions & 0 deletions
62
plugins/tasks/mock/src/main/java/com/walmartlabs/concord/plugins/mock/MockTaskProvider.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
package com.walmartlabs.concord.plugins.mock; | ||
|
||
/*- | ||
* ***** | ||
* Concord | ||
* ----- | ||
* Copyright (C) 2017 - 2023 Walmart Inc. | ||
* ----- | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
* ===== | ||
*/ | ||
|
||
|
||
import com.walmartlabs.concord.runtime.v2.sdk.Context; | ||
import com.walmartlabs.concord.runtime.v2.sdk.Task; | ||
import com.walmartlabs.concord.runtime.v2.sdk.TaskProvider; | ||
import org.eclipse.sisu.Priority; | ||
|
||
import javax.inject.Inject; | ||
import java.util.Collections; | ||
import java.util.Set; | ||
|
||
@Priority(-1) | ||
public class MockTaskProvider implements TaskProvider { | ||
|
||
private final MockDefinitionProvider mockDefinitionProvider; | ||
|
||
@Inject | ||
public MockTaskProvider(MockDefinitionProvider mockDefinitionProvider) { | ||
this.mockDefinitionProvider = mockDefinitionProvider; | ||
} | ||
|
||
@Override | ||
public Task createTask(Context ctx, String key) { | ||
MockDefinition def = mockDefinitionProvider.get(ctx, key); | ||
if (def == null) { | ||
return null; | ||
} | ||
|
||
return new MockTask(def); | ||
} | ||
|
||
@Override | ||
public boolean hasTask(String key) { | ||
return false; | ||
} | ||
|
||
@Override | ||
public Set<String> names() { | ||
return Collections.emptySet(); | ||
} | ||
} |