Skip to content

Commit

Permalink
Merge pull request #35 from emmartins/AS7-3570
Browse files Browse the repository at this point in the history
adding code that ensures ejb-name is set for ebj bound parsers, and a co...
  • Loading branch information
jfclere committed Jul 28, 2012
2 parents 28483ff + c422a34 commit 6a9fbe9
Show file tree
Hide file tree
Showing 4 changed files with 114 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@
*/
package org.jboss.metadata.ejb.parser.jboss.ejb3;

import java.util.HashSet;
import java.util.Set;

import org.jboss.metadata.ejb.parser.spec.AbstractMetaDataParser;
import org.jboss.metadata.ejb.parser.spec.EjbJarElement;

Expand Down Expand Up @@ -56,4 +59,16 @@ protected void processElement(MD metaData, XMLStreamReader reader, final Propert
}
super.processElement(metaData, reader, propertyReplacer);
}

@Override
protected void processElements(MD metaData, XMLStreamReader reader, PropertyReplacer propertyReplacer)
throws XMLStreamException {
super.processElements(metaData, reader, propertyReplacer);
if (metaData.getEjbName() == null) {
Set<EjbJarElement> required = new HashSet<EjbJarElement>();
required.add(EjbJarElement.EJB_NAME);
throw missingRequiredElement(reader, required);
}
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
/*
* JBoss, Home of Professional Open Source
* Copyright 2012, JBoss Inc., and individual contributors as indicated
* by the @authors tag. See the copyright.txt in the distribution for a
* full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.metadata.ejb.test.parser.jboss.ejb3;

import java.util.HashMap;
import java.util.Map;

import javax.xml.stream.XMLStreamException;

import org.jboss.metadata.ejb.parser.jboss.ejb3.IIOPMetaDataParser;
import org.jboss.metadata.ejb.parser.spec.AbstractMetaDataParser;
import org.jboss.metadata.ejb.spec.EjbJarMetaData;
import org.jboss.metadata.ejb.test.common.UnmarshallingHelper;
import org.jboss.test.metadata.ejb.AbstractEJBEverythingTest;

/**
* Tests that AbstractEJBBoundMetaDataParser fails when ejb name is not set.
*
* More info at AS7-3570.
*
* @author Eduardo Martins
*/
public class AbstractEJBBoundMetaDataParserUnitTestCase extends AbstractEJBEverythingTest {

public AbstractEJBBoundMetaDataParserUnitTestCase(String name) {
super(name);
}

public void testInvalidXML() throws Exception {
IIOPMetaDataParser parser = new IIOPMetaDataParser();
Map<String, AbstractMetaDataParser<?>> parsers = new HashMap<String, AbstractMetaDataParser<?>>();
parsers.put("urn:iiop", parser);
try {
UnmarshallingHelper.unmarshalJboss(EjbJarMetaData.class, "../test/parser/jboss/ejb3/invalid-jboss-ejb3.xml",
parsers);
fail("The unmarshalling of the XML did not throw the expected expection");
} catch (XMLStreamException e) {

}
}

public void testValidXML() throws Exception {
IIOPMetaDataParser parser = new IIOPMetaDataParser();
Map<String, AbstractMetaDataParser<?>> parsers = new HashMap<String, AbstractMetaDataParser<?>>();
parsers.put("urn:iiop", parser);
try {
UnmarshallingHelper.unmarshalJboss(EjbJarMetaData.class, "../test/parser/jboss/ejb3/valid-jboss-ejb3.xml", parsers);
} catch (Throwable e) {
e.printStackTrace();
fail("The unmarshalling of the XML thrown an unexpected exception");
}
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?xml version="1.0"?>
<jboss:ejb-jar xmlns:jboss="http://www.jboss.com/xml/ns/javaee"
xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:iiop="urn:iiop"
xsi:schemaLocation="http://www.jboss.com/xml/ns/javaee http://www.jboss.org/j2ee/schema/jboss-ejb3-2_0.xsd
http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/ejb-jar_3_1.xsd"
version="3.1" impl-version="2.0">
<assembly-descriptor>
<iiop:ior-security-config>
<!-- <ejb-name>X</ejb-name> -->
</iiop:ior-security-config>
</assembly-descriptor>
</jboss:ejb-jar>
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?xml version="1.0"?>
<jboss:ejb-jar xmlns:jboss="http://www.jboss.com/xml/ns/javaee"
xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:iiop="urn:iiop"
xsi:schemaLocation="http://www.jboss.com/xml/ns/javaee http://www.jboss.org/j2ee/schema/jboss-ejb3-2_0.xsd
http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/ejb-jar_3_1.xsd"
version="3.1" impl-version="2.0">
<assembly-descriptor>
<iiop:ior-security-config>
<ejb-name>X</ejb-name>
</iiop:ior-security-config>
</assembly-descriptor>
</jboss:ejb-jar>

0 comments on commit 6a9fbe9

Please sign in to comment.