Skip to content

Commit

Permalink
Merge pull request #2173 from FedeAmdan/mule-9066
Browse files Browse the repository at this point in the history
MULE-9066: Adding validation when set-property and set-variable have …
  • Loading branch information
marianogonzalez committed Nov 18, 2015
2 parents 2ec3a27 + a7358f5 commit 766e622
Show file tree
Hide file tree
Showing 6 changed files with 84 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,9 @@ public Object clone() throws CloneNotSupportedException

public void setIdentifier(String identifier)
{
if (identifier == null)
if (StringUtils.isBlank(identifier))
{
throw new IllegalArgumentException("Key must not be null");
throw new IllegalArgumentException("Key cannot be blank");
}
this.identifierEvaluator = new AttributeEvaluator(identifier);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,12 @@ public void testAddVariableWithNullKey() throws InitialisationException, Transfo
addVariableTransformer.setIdentifier(null);
}

@Test(expected = IllegalArgumentException.class)
public void testAddVariableWithEmptyKey() throws InitialisationException, TransformerException
{
addVariableTransformer.setIdentifier("");
}

@Test(expected = IllegalArgumentException.class)
public void testAddVariableWithNullValue() throws InitialisationException, TransformerException
{
Expand Down
10 changes: 8 additions & 2 deletions modules/spring-config/src/main/resources/META-INF/mule.xsd
Original file line number Diff line number Diff line change
Expand Up @@ -4471,7 +4471,7 @@
<xsd:complexType name="setPropertyType">
<xsd:complexContent>
<xsd:extension base="abstractAddPropertyTransformerType">
<xsd:attribute name="propertyName" type="attributeType" use="required"/>
<xsd:attribute name="propertyName" type="nonEmptyAttributeType" use="required"/>
<xsd:attribute name="value" type="attributeType" use="required"/>
</xsd:extension>
</xsd:complexContent>
Expand Down Expand Up @@ -4517,7 +4517,7 @@
<xsd:complexType name="setVariableType">
<xsd:complexContent>
<xsd:extension base="abstractAddPropertyTransformerType">
<xsd:attribute name="variableName" type="attributeType" use="required"/>
<xsd:attribute name="variableName" type="nonEmptyAttributeType" use="required"/>
<xsd:attribute name="value" type="attributeType" use="required"/>
</xsd:extension>
</xsd:complexContent>
Expand Down Expand Up @@ -8455,6 +8455,12 @@
<xsd:restriction base="xsd:string"/>
</xsd:simpleType>

<xsd:simpleType name="nonEmptyAttributeType">
<xsd:restriction base="xsd:string">
<xsd:minLength value="1"/>
</xsd:restriction>
</xsd:simpleType>

<!--==============================================================-->
<!-- Connector support -->
<!--==============================================================-->
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
* Copyright (c) MuleSoft, Inc. All rights reserved. http://www.mulesoft.com
* The software in this package is published under the terms of the CPAL v1.0
* license, a copy of which has been included with this distribution in the
* LICENSE.txt file.
*/
package org.mule.properties;

import org.mule.api.MuleContext;
import org.mule.api.config.ConfigurationException;
import org.mule.config.spring.SpringXmlConfigurationBuilder;
import org.mule.context.DefaultMuleContextFactory;
import org.mule.tck.junit4.AbstractMuleTestCase;
import java.util.Arrays;
import java.util.Collection;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;

@RunWith(Parameterized.class)
public class InvalidSetVariableTestCase extends AbstractMuleTestCase
{
private String muleConfigPath;

@Parameterized.Parameters
public static Collection<Object[]> data() {
return Arrays.asList(new Object[][] {{"org/mule/properties/invalid-set-property.xml"}, {"org/mule/properties/invalid-set-variable.xml"}});
}

public InvalidSetVariableTestCase(String muleConfigPath)
{
this.muleConfigPath = muleConfigPath;
}

@Test(expected = ConfigurationException.class)
public void emptyVariableNameValidatedBySchema() throws Exception
{
MuleContext context = new DefaultMuleContextFactory().createMuleContext();
SpringXmlConfigurationBuilder builder = new SpringXmlConfigurationBuilder(muleConfigPath);
builder.configure(context);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<mule xmlns="http://www.mulesoft.org/schema/mule/core"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:vm="http://www.mulesoft.org/schema/mule/vm"
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/vm http://www.mulesoft.org/schema/mule/vm/current/mule-vm.xsd">

<flow name="main">
<vm:inbound-endpoint path="testInput" exchange-pattern="request-response"/>
<set-property propertyName="" value="test" />
</flow>
</mule>
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<mule xmlns="http://www.mulesoft.org/schema/mule/core"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:vm="http://www.mulesoft.org/schema/mule/vm"
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/vm http://www.mulesoft.org/schema/mule/vm/current/mule-vm.xsd">

<flow name="main">
<vm:inbound-endpoint path="testInput" exchange-pattern="request-response"/>
<set-variable variableName="" value="test" />
</flow>
</mule>

0 comments on commit 766e622

Please sign in to comment.