Repository: tomee
Updated Branches:
  refs/heads/tomee-1.7.x f949ad718 -> 7e3094233


TOMEE-2154 add tests, and correct some issues with parsing


Project: http://git-wip-us.apache.org/repos/asf/tomee/repo
Commit: http://git-wip-us.apache.org/repos/asf/tomee/commit/7e309423
Tree: http://git-wip-us.apache.org/repos/asf/tomee/tree/7e309423
Diff: http://git-wip-us.apache.org/repos/asf/tomee/diff/7e309423

Branch: refs/heads/tomee-1.7.x
Commit: 7e30942333c3632a347baf5cace1a700ab21ecc3
Parents: f949ad7
Author: Jonathan Gallimore <[email protected]>
Authored: Sat Dec 2 00:25:10 2017 +0000
Committer: Jonathan Gallimore <[email protected]>
Committed: Sat Dec 2 00:25:10 2017 +0000

----------------------------------------------------------------------
 .../apache/openejb/config/sys/StackHandler.java |  7 +++
 .../config/ConfigurationFactoryTest.java        | 36 +++++++++++++
 .../resource/PropertiesProviderFromXmlTest.java | 53 ++++++++++++++++++++
 3 files changed, 96 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tomee/blob/7e309423/container/openejb-core/src/main/java/org/apache/openejb/config/sys/StackHandler.java
----------------------------------------------------------------------
diff --git 
a/container/openejb-core/src/main/java/org/apache/openejb/config/sys/StackHandler.java
 
b/container/openejb-core/src/main/java/org/apache/openejb/config/sys/StackHandler.java
index 3ac18c5..c6dbc38 100644
--- 
a/container/openejb-core/src/main/java/org/apache/openejb/config/sys/StackHandler.java
+++ 
b/container/openejb-core/src/main/java/org/apache/openejb/config/sys/StackHandler.java
@@ -155,6 +155,10 @@ public class StackHandler extends DefaultHandler {
                 service.setClasspath(attributes.getValue("classpath"));
             }
 
+            if (attributes.getValue("properties-provider") != null) {
+                
service.setPropertiesProvider(attributes.getValue("properties-provider"));
+            }
+
             checkAttributes(attributes, getAttributes());
         }
 
@@ -197,6 +201,9 @@ public class StackHandler extends DefaultHandler {
             service.setPostConstruct(attributes.getValue("post-construct"));
             service.setPreDestroy(attributes.getValue("pre-destroy"));
             
service.setPropertiesProvider(attributes.getValue("property-provider"));
+            if (service.getPropertiesProvider() == null) {
+                
service.setPropertiesProvider(attributes.getValue("properties-provider"));
+            }
 
             final String aliases = attributes.getValue("aliases");
             if (aliases != null) {

http://git-wip-us.apache.org/repos/asf/tomee/blob/7e309423/container/openejb-core/src/test/java/org/apache/openejb/config/ConfigurationFactoryTest.java
----------------------------------------------------------------------
diff --git 
a/container/openejb-core/src/test/java/org/apache/openejb/config/ConfigurationFactoryTest.java
 
b/container/openejb-core/src/test/java/org/apache/openejb/config/ConfigurationFactoryTest.java
index f0b88c8..4cf8a79 100755
--- 
a/container/openejb-core/src/test/java/org/apache/openejb/config/ConfigurationFactoryTest.java
+++ 
b/container/openejb-core/src/test/java/org/apache/openejb/config/ConfigurationFactoryTest.java
@@ -17,9 +17,12 @@
 package org.apache.openejb.config;
 
 import org.apache.openejb.OpenEJBException;
+import org.apache.openejb.api.resource.PropertiesResourceProvider;
+import org.apache.openejb.assembler.classic.ContainerInfo;
 import org.apache.openejb.assembler.classic.EjbJarInfo;
 import org.apache.openejb.assembler.classic.OpenEjbConfiguration;
 import org.apache.openejb.assembler.classic.WebAppInfo;
+import org.apache.openejb.config.sys.Container;
 import org.apache.openejb.config.sys.Deployments;
 import org.apache.openejb.jee.EjbJar;
 import org.apache.openejb.jee.WebApp;
@@ -123,4 +126,37 @@ public class ConfigurationFactoryTest {
         final URL[] urls = cl.getURLs();
         assertEquals(urls[0], new File(path).toURI().normalize().toURL());
     }
+
+    @Test
+    public void testUsePropertiesProviderWhenCreatingAContainer() throws 
Exception {
+        final ConfigurationFactory configurationFactory = new 
ConfigurationFactory();
+        final Container container = new Container();
+        container.setPropertiesProvider(MyPropertiesProvider.class.getName());
+        container.setCtype("STATELESS");
+
+        final ContainerInfo containerInfo = 
configurationFactory.createContainerInfo(container);
+        assertEquals("newproperty", 
containerInfo.properties.getProperty("test"));
+    }
+
+    public static class MyPropertiesProvider implements 
PropertiesResourceProvider {
+
+        private Properties properties;
+
+        @Override
+        public Properties provides() {
+            final Properties p = new Properties();
+            p.putAll(properties);
+            p.setProperty("test", "newproperty");
+
+            return p;
+        }
+
+        public Properties getProperties() {
+            return properties;
+        }
+
+        public void setProperties(Properties properties) {
+            this.properties = properties;
+        }
+    }
 }

http://git-wip-us.apache.org/repos/asf/tomee/blob/7e309423/container/openejb-core/src/test/java/org/apache/openejb/resource/PropertiesProviderFromXmlTest.java
----------------------------------------------------------------------
diff --git 
a/container/openejb-core/src/test/java/org/apache/openejb/resource/PropertiesProviderFromXmlTest.java
 
b/container/openejb-core/src/test/java/org/apache/openejb/resource/PropertiesProviderFromXmlTest.java
new file mode 100644
index 0000000..3c8d687
--- /dev/null
+++ 
b/container/openejb-core/src/test/java/org/apache/openejb/resource/PropertiesProviderFromXmlTest.java
@@ -0,0 +1,53 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.
+ */
+package org.apache.openejb.resource;
+
+import org.apache.openejb.config.sys.Container;
+import org.apache.openejb.config.sys.JaxbOpenejb;
+import org.apache.openejb.config.sys.Openejb;
+import org.apache.openejb.config.sys.Resource;
+import org.junit.Test;
+import org.xml.sax.InputSource;
+import org.xml.sax.SAXException;
+
+import javax.xml.parsers.ParserConfigurationException;
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
+
+import static org.junit.Assert.assertEquals;
+
+public class PropertiesProviderFromXmlTest {
+    @Test
+    public void ensureAliasesAreParsed() throws IOException, SAXException, 
ParserConfigurationException {
+        final String xml = "<?xml version=\"1.0\"?>" +
+            "<tomee>" +
+            "   <Resource id=\"foo\" type=\"DataSource\" 
properties-provider=\"org.acme.Foo\"/>" +
+            "   <Container id=\"bar\" ctype=\"STATELESS\" 
properties-provider=\"org.acme.Foo\"/>" +
+            "</tomee>";
+
+        final Openejb openejb = JaxbOpenejb.readConfig(new InputSource(new 
ByteArrayInputStream(xml.getBytes())));
+        assertEquals(1, openejb.getResource().size());
+
+        final Resource resource = openejb.getResource().iterator().next();
+        assertEquals("foo", resource.getId());
+        assertEquals("org.acme.Foo", resource.getPropertiesProvider());
+
+        final Container container = openejb.getContainer().iterator().next();
+        assertEquals("bar", container.getId());
+        assertEquals("org.acme.Foo", container.getPropertiesProvider());
+    }
+}

Reply via email to