Commit 4d7b57b0 authored by Danijel Dragicevic's avatar Danijel Dragicevic

Initial commit.

parents
# AssertObjectEquals Extension
Add description ...
...
...
Add this dependency to your application pom.xml
```
<groupId>de.codecentric.mule.modules</groupId>
<artifactId>assert-object-equals-module</artifactId>
<version>1.0.0-SNAPSHOT</version>
<classifier>mule-plugin</classifier>
```
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<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>
<groupId>de.codecentric.mule.modules</groupId>
<artifactId>assert-object-equals-module</artifactId>
<version>1.0.0-SNAPSHOT</version>
<packaging>mule-extension</packaging>
<name>AssertObjectEquals Extension</name>
<parent>
<groupId>org.mule.extensions</groupId>
<artifactId>mule-modules-parent</artifactId>
<version>1.1.3</version>
</parent>
</project>
package de.codecentric.mule.modules.assertobjectequals.internal;
import org.mule.runtime.extension.api.annotation.Operations;
import org.mule.runtime.extension.api.annotation.connectivity.ConnectionProviders;
import org.mule.runtime.extension.api.annotation.param.Parameter;
/**
* This class represents an extension configuration, values set in this class are commonly used across multiple
* operations since they represent something core from the extension.
*/
@Operations(AssertObjectEqualsOperations.class)
@ConnectionProviders(AssertObjectEqualsConnectionProvider.class)
public class AssertObjectEqualsConfiguration {
@Parameter
private String configId;
public String getConfigId(){
return configId;
}
}
package de.codecentric.mule.modules.assertobjectequals.internal;
/**
* This class represents an extension connection just as example (there is no real connection with anything here c:).
*/
public final class AssertObjectEqualsConnection {
private final String id;
public AssertObjectEqualsConnection(String id) {
this.id = id;
}
public String getId() {
return id;
}
public void invalidate() {
// do something to invalidate this connection!
}
}
package de.codecentric.mule.modules.assertobjectequals.internal;
import org.mule.runtime.api.connection.ConnectionException;
import org.mule.runtime.extension.api.annotation.param.Parameter;
import org.mule.runtime.extension.api.annotation.param.Optional;
import org.mule.runtime.api.connection.ConnectionValidationResult;
import org.mule.runtime.api.connection.PoolingConnectionProvider;
import org.mule.runtime.api.connection.ConnectionProvider;
import org.mule.runtime.api.connection.CachedConnectionProvider;
import org.mule.runtime.extension.api.annotation.param.display.DisplayName;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* This class (as it's name implies) provides connection instances and the funcionality to disconnect and validate those
* connections.
* <p>
* All connection related parameters (values required in order to create a connection) must be
* declared in the connection providers.
* <p>
* This particular example is a {@link PoolingConnectionProvider} which declares that connections resolved by this provider
* will be pooled and reused. There are other implementations like {@link CachedConnectionProvider} which lazily creates and
* caches connections or simply {@link ConnectionProvider} if you want a new connection each time something requires one.
*/
public class AssertObjectEqualsConnectionProvider implements PoolingConnectionProvider<AssertObjectEqualsConnection> {
private final Logger LOGGER = LoggerFactory.getLogger(AssertObjectEqualsConnectionProvider.class);
/**
* A parameter that is always required to be configured.
*/
@Parameter
private String requiredParameter;
/**
* A parameter that is not required to be configured by the user.
*/
@DisplayName("Friendly Name")
@Parameter
@Optional(defaultValue = "100")
private int optionalParameter;
@Override
public AssertObjectEqualsConnection connect() throws ConnectionException {
return new AssertObjectEqualsConnection(requiredParameter + ":" + optionalParameter);
}
@Override
public void disconnect(AssertObjectEqualsConnection connection) {
try {
connection.invalidate();
} catch (Exception e) {
LOGGER.error("Error while disconnecting [" + connection.getId() + "]: " + e.getMessage(), e);
}
}
@Override
public ConnectionValidationResult validate(AssertObjectEqualsConnection connection) {
return ConnectionValidationResult.success();
}
}
package de.codecentric.mule.modules.assertobjectequals.internal;
import org.mule.runtime.extension.api.annotation.Extension;
import org.mule.runtime.extension.api.annotation.Configurations;
import org.mule.runtime.extension.api.annotation.dsl.xml.Xml;
/**
* This is the main class of an extension, is the entry point from which configurations, connection providers, operations
* and sources are going to be declared.
*/
@Xml(prefix = "assertobjectequals")
@Extension(name = "AssertObjectEquals")
@Configurations(AssertObjectEqualsConfiguration.class)
public class AssertObjectEqualsExtension {
}
package de.codecentric.mule.modules.assertobjectequals.internal;
import static org.mule.runtime.extension.api.annotation.param.MediaType.ANY;
import org.mule.runtime.extension.api.annotation.param.MediaType;
import org.mule.runtime.extension.api.annotation.param.Config;
import org.mule.runtime.extension.api.annotation.param.Connection;
/**
* This class is a container for operations, every public method in this class will be taken as an extension operation.
*/
public class AssertObjectEqualsOperations {
/**
* Example of an operation that uses the configuration and a connection instance to perform some action.
*/
@MediaType(value = ANY, strict = false)
public String retrieveInfo(@Config AssertObjectEqualsConfiguration configuration, @Connection AssertObjectEqualsConnection connection){
return "Using Configuration [" + configuration.getConfigId() + "] with Connection id [" + connection.getId() + "]";
}
/**
* Example of a simple operation that receives a string parameter and returns a new string message that will be set on the payload.
*/
@MediaType(value = ANY, strict = false)
public String sayHi(String person) {
return buildHelloMessage(person);
}
/**
* Private Methods are not exposed as operations
*/
private String buildHelloMessage(String person) {
return "Hello " + person + "!!!";
}
}
package de.codecentric.mule.modules.assertobjectequals;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.core.Is.is;
import org.mule.functional.junit4.MuleArtifactFunctionalTestCase;
import org.junit.Test;
public class AssertObjectEqualsOperationsTestCase extends MuleArtifactFunctionalTestCase {
/**
* Specifies the mule config xml with the flows that are going to be executed in the tests, this file lives in the test resources.
*/
@Override
protected String getConfigFile() {
return "test-mule-config.xml";
}
@Test
public void executeSayHiOperation() throws Exception {
String payloadValue = ((String) flowRunner("sayHiFlow").run()
.getMessage()
.getPayload()
.getValue());
assertThat(payloadValue, is("Hello Mariano Gonzalez!!!"));
}
@Test
public void executeRetrieveInfoOperation() throws Exception {
String payloadValue = ((String) flowRunner("retrieveInfoFlow")
.run()
.getMessage()
.getPayload()
.getValue());
assertThat(payloadValue, is("Using Configuration [configId] with Connection id [aValue:100]"));
}
}
<mule xmlns="http://www.mulesoft.org/schema/mule/core"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:assertobjectequals="http://www.mulesoft.org/schema/mule/assertobjectequals"
xsi:schemaLocation="http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd
http://www.mulesoft.org/schema/mule/assertobjectequals http://www.mulesoft.org/schema/mule/assertobjectequals/current/mule-assertobjectequals.xsd">
<assertobjectequals:config name="config" configId="configId">
<assertobjectequals:connection requiredParameter="aValue" />
</assertobjectequals:config>
<flow name="sayHiFlow">
<assertobjectequals:say-hi person="Mariano Gonzalez"/>
</flow>
<flow name="retrieveInfoFlow">
<assertobjectequals:retrieve-info config-ref="config"/>
</flow>
</mule>
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment