Repository: tomee
Updated Branches:
  refs/heads/master 0c3ff0ae1 -> f742a4f0e


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/f742a4f0
Tree: http://git-wip-us.apache.org/repos/asf/tomee/tree/f742a4f0
Diff: http://git-wip-us.apache.org/repos/asf/tomee/diff/f742a4f0

Branch: refs/heads/master
Commit: f742a4f0e66a03013b52bf85196d1cba3693bfb3
Parents: 0c3ff0a
Author: Jonathan Gallimore <[email protected]>
Authored: Sat Dec 2 00:25:10 2017 +0000
Committer: Jonathan Gallimore <[email protected]>
Committed: Sat Dec 2 00:26:18 2017 +0000

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


http://git-wip-us.apache.org/repos/asf/tomee/blob/f742a4f0/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 63da4dc..3703503 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
@@ -187,6 +187,10 @@ public class StackHandler extends DefaultHandler {
                 service.setClasspathAPI(attributes.getValue("classpath-api"));
             }
 
+            if (attributes.getValue("properties-provider") != null) {
+                
service.setPropertiesProvider(attributes.getValue("properties-provider"));
+            }
+
             checkAttributes(attributes, getAttributes());
         }
 

http://git-wip-us.apache.org/repos/asf/tomee/blob/f742a4f0/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 4cce410..b5bf451 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;
@@ -125,4 +128,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/f742a4f0/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