Author: chris.laprun(a)jboss.com
Date: 2011-05-26 09:15:07 -0400 (Thu, 26 May 2011)
New Revision: 6567
Added:
components/wsrp/trunk/jcr-impl/src/test/java/org/gatein/wsrp/producer/
components/wsrp/trunk/jcr-impl/src/test/java/org/gatein/wsrp/producer/config/
components/wsrp/trunk/jcr-impl/src/test/java/org/gatein/wsrp/producer/config/JCRProducerConfigurationServiceTestCase.java
components/wsrp/trunk/producer/src/test/java/org/gatein/wsrp/producer/config/JAXBProducerConfigurationTestCase.java
Modified:
components/wsrp/trunk/jcr-impl/src/main/java/org/gatein/wsrp/producer/config/mapping/RegistrationRequirementsMapping.java
components/wsrp/trunk/producer/src/test/java/org/gatein/wsrp/producer/config/ProducerConfigurationTestCase.java
Log:
- GTNWSRP-232: do not attempt to work with the RegistrationPolicy if it is null!
- Added test cases.
Modified:
components/wsrp/trunk/jcr-impl/src/main/java/org/gatein/wsrp/producer/config/mapping/RegistrationRequirementsMapping.java
===================================================================
---
components/wsrp/trunk/jcr-impl/src/main/java/org/gatein/wsrp/producer/config/mapping/RegistrationRequirementsMapping.java 2011-05-26
11:45:08 UTC (rev 6566)
+++
components/wsrp/trunk/jcr-impl/src/main/java/org/gatein/wsrp/producer/config/mapping/RegistrationRequirementsMapping.java 2011-05-26
13:15:07 UTC (rev 6567)
@@ -81,13 +81,16 @@
setRegistrationRequired(registrationRequirements.isRegistrationRequired());
setRegistrationRequiredForFullDescription(registrationRequirements.isRegistrationRequiredForFullDescription());
RegistrationPolicy policy = registrationRequirements.getPolicy();
- setPolicyClassName(policy.getClassName());
+ if (policy != null)
+ {
+ setPolicyClassName(policy.getClassName());
- RegistrationPolicy unwrap = RegistrationPolicyWrapper.unwrap(policy);
- if (unwrap instanceof DefaultRegistrationPolicy)
- {
- DefaultRegistrationPolicy drp = (DefaultRegistrationPolicy)unwrap;
- setValidatorClassName(drp.getValidator().getClass().getName());
+ RegistrationPolicy unwrap = RegistrationPolicyWrapper.unwrap(policy);
+ if (unwrap instanceof DefaultRegistrationPolicy)
+ {
+ DefaultRegistrationPolicy drp = (DefaultRegistrationPolicy)unwrap;
+ setValidatorClassName(drp.getValidator().getClass().getName());
+ }
}
// first clear persisted properties
Added:
components/wsrp/trunk/jcr-impl/src/test/java/org/gatein/wsrp/producer/config/JCRProducerConfigurationServiceTestCase.java
===================================================================
---
components/wsrp/trunk/jcr-impl/src/test/java/org/gatein/wsrp/producer/config/JCRProducerConfigurationServiceTestCase.java
(rev 0)
+++
components/wsrp/trunk/jcr-impl/src/test/java/org/gatein/wsrp/producer/config/JCRProducerConfigurationServiceTestCase.java 2011-05-26
13:15:07 UTC (rev 6567)
@@ -0,0 +1,63 @@
+/*
+* JBoss, a division of Red Hat
+* Copyright 2008, Red Hat Middleware, LLC, 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.gatein.wsrp.producer.config;
+
+import org.chromattic.api.ChromatticBuilder;
+import org.gatein.wsrp.jcr.BaseChromatticPersister;
+
+import java.net.URL;
+
+/**
+ * @author <a href="mailto:chris.laprun@jboss.com">Chris
Laprun</a>
+ * @version $Revision$
+ */
+public class JCRProducerConfigurationServiceTestCase extends
ProducerConfigurationTestCase
+{
+ private JCRProducerConfigurationService service;
+
+ @Override
+ public void setUp() throws Exception
+ {
+ String workspaceName = "/wsrp-jcr-test" + Math.round(Math.abs(100000 *
Math.random()));
+ BaseChromatticPersister persister = new BaseChromatticPersister(workspaceName)
+ {
+ @Override
+ protected void setBuilderOptions(ChromatticBuilder builder)
+ {
+ builder.setOptionValue(ChromatticBuilder.ROOT_NODE_PATH, workspaceName);
+ builder.setOptionValue(ChromatticBuilder.ROOT_NODE_TYPE,
"nt:unstructured");
+ builder.setOptionValue(ChromatticBuilder.CREATE_ROOT_NODE, true);
+ }
+ };
+ persister.initializeBuilderFor(JCRProducerConfigurationService.mappingClasses);
+ service = new JCRProducerConfigurationService(persister);
+ }
+
+ @Override
+ protected ProducerConfiguration getProducerConfiguration(URL location) throws
Exception
+ {
+ service.setDefaultConfigurationIS(location.openStream());
+ service.loadConfiguration();
+ return service.getConfiguration();
+ }
+}
Added:
components/wsrp/trunk/producer/src/test/java/org/gatein/wsrp/producer/config/JAXBProducerConfigurationTestCase.java
===================================================================
---
components/wsrp/trunk/producer/src/test/java/org/gatein/wsrp/producer/config/JAXBProducerConfigurationTestCase.java
(rev 0)
+++
components/wsrp/trunk/producer/src/test/java/org/gatein/wsrp/producer/config/JAXBProducerConfigurationTestCase.java 2011-05-26
13:15:07 UTC (rev 6567)
@@ -0,0 +1,57 @@
+/*
+* JBoss, a division of Red Hat
+* Copyright 2008, Red Hat Middleware, LLC, 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.gatein.wsrp.producer.config;
+
+import org.gatein.wsrp.producer.config.impl.xml.ProducerConfigurationFactory;
+import org.jboss.xb.binding.JBossXBException;
+import org.jboss.xb.binding.ObjectModelFactory;
+import org.jboss.xb.binding.Unmarshaller;
+import org.jboss.xb.binding.UnmarshallerFactory;
+
+import java.io.IOException;
+import java.net.URL;
+
+/**
+ * @author <a href="mailto:chris.laprun@jboss.com">Chris
Laprun</a>
+ * @version $Revision$
+ */
+public class JAXBProducerConfigurationTestCase extends ProducerConfigurationTestCase
+{
+ private Unmarshaller unmarshaller;
+ private ObjectModelFactory factory;
+
+ protected void setUp() throws Exception
+ {
+ unmarshaller = UnmarshallerFactory.newInstance().newUnmarshaller();
+ factory = new ProducerConfigurationFactory();
+ unmarshaller.setEntityResolver(new TestEntityResolver());
+ }
+
+ protected ProducerConfiguration getProducerConfiguration(URL location) throws
JBossXBException, IOException
+ {
+ Object o = unmarshaller.unmarshal(location.openStream(), factory, null);
+ assertNotNull(o);
+ assertTrue(o instanceof ProducerConfiguration);
+ return (ProducerConfiguration)o;
+ }
+}
Modified:
components/wsrp/trunk/producer/src/test/java/org/gatein/wsrp/producer/config/ProducerConfigurationTestCase.java
===================================================================
---
components/wsrp/trunk/producer/src/test/java/org/gatein/wsrp/producer/config/ProducerConfigurationTestCase.java 2011-05-26
11:45:08 UTC (rev 6566)
+++
components/wsrp/trunk/producer/src/test/java/org/gatein/wsrp/producer/config/ProducerConfigurationTestCase.java 2011-05-26
13:15:07 UTC (rev 6567)
@@ -31,15 +31,10 @@
import org.gatein.registration.policies.RegistrationPropertyValidator;
import org.gatein.wsrp.WSRPConstants;
import org.gatein.wsrp.producer.config.impl.ProducerConfigurationImpl;
-import org.gatein.wsrp.producer.config.impl.xml.ProducerConfigurationFactory;
import org.gatein.wsrp.producer.config.impl.xml.ProducerConfigurationProvider;
import org.gatein.wsrp.registration.LocalizedString;
import org.gatein.wsrp.registration.RegistrationPropertyDescription;
-import org.jboss.xb.binding.JBossXBException;
-import org.jboss.xb.binding.ObjectModelFactory;
import org.jboss.xb.binding.ObjectModelProvider;
-import org.jboss.xb.binding.Unmarshaller;
-import org.jboss.xb.binding.UnmarshallerFactory;
import org.jboss.xb.binding.XercesXsMarshaller;
import org.jboss.xb.binding.sunday.unmarshalling.DefaultSchemaResolver;
import org.xml.sax.SAXException;
@@ -64,10 +59,8 @@
* @version $Revision: 10408 $
* @since 2.6
*/
-public class ProducerConfigurationTestCase extends TestCase
+public abstract class ProducerConfigurationTestCase extends TestCase
{
- private Unmarshaller unmarshaller;
- private ObjectModelFactory factory;
private static DefaultSchemaResolver RESOLVER;
@@ -79,13 +72,6 @@
RESOLVER.addSchemaLocation("http://www.gatein.org/xml/ns/gatein_wsrp...;,
"xsd/gatein_wsrp_producer_1_0.xsd");
}
- protected void setUp() throws Exception
- {
- unmarshaller = UnmarshallerFactory.newInstance().newUnmarshaller();
- factory = new ProducerConfigurationFactory();
- unmarshaller.setEntityResolver(new
org.gatein.wsrp.producer.config.TestEntityResolver());
- }
-
public void testCustomPolicyUnmarshalling() throws Exception
{
ProducerConfiguration producerConfiguration =
getProducerConfiguration("custom-policy.xml");
@@ -203,13 +189,13 @@
}
}
- public void testUseStrictMode() throws IOException, JBossXBException
+ public void testUseStrictMode() throws Exception
{
ProducerConfiguration producerConfiguration =
getProducerConfiguration("strict-mode.xml");
assertFalse(producerConfiguration.isUsingStrictMode());
}
- public void testChangeListeners() throws IOException, JBossXBException
+ public void testChangeListeners() throws Exception
{
ProducerConfiguration producerConfiguration =
getProducerConfiguration("minimal.xml");
assertTrue(producerConfiguration.isUsingStrictMode());
@@ -227,7 +213,7 @@
assertTrue(listener.called);
}
- public void testSaveAndReload() throws IOException, ParserConfigurationException,
SAXException, JBossXBException
+ public void testSaveAndReload() throws Exception
{
ProducerConfiguration configuration = new ProducerConfigurationImpl();
configuration.setUsingStrictMode(false);
@@ -255,7 +241,7 @@
writeConfigToFile(configuration, tmp);
- configuration = getProducerConfiguration(tmp.toURL());
+ configuration = getProducerConfiguration(tmp.toURI().toURL());
assertFalse(configuration.isUsingStrictMode());
@@ -315,7 +301,7 @@
configFile.close();
}
- private ProducerConfiguration getProducerConfiguration(String fileName) throws
JBossXBException, IOException
+ protected ProducerConfiguration getProducerConfiguration(String fileName) throws
Exception
{
URL location =
Thread.currentThread().getContextClassLoader().getResource(fileName);
assertNotNull(location);
@@ -324,13 +310,7 @@
return getProducerConfiguration(location);
}
- private ProducerConfiguration getProducerConfiguration(URL location) throws
JBossXBException, IOException
- {
- Object o = unmarshaller.unmarshal(location.openStream(), factory, null);
- assertNotNull(o);
- assertTrue(o instanceof ProducerConfiguration);
- return (ProducerConfiguration)o;
- }
+ protected abstract ProducerConfiguration getProducerConfiguration(URL location) throws
Exception;
private void checkRegistrationProperty(ProducerRegistrationRequirements requirements,
int index)
{