shiro-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jbunt...@apache.org
Subject svn commit: r1227045 - in /shiro/trunk/core/src/test/java/org/apache/shiro/jndi: ./ JndiObjectFactoryTest.java
Date Wed, 04 Jan 2012 05:07:37 GMT
Author: jbunting
Date: Wed Jan  4 05:07:36 2012
New Revision: 1227045

URL: http://svn.apache.org/viewvc?rev=1227045&view=rev
Log:
SHIRO-217: Added unit test for JndiObjectFactory


Added:
    shiro/trunk/core/src/test/java/org/apache/shiro/jndi/
    shiro/trunk/core/src/test/java/org/apache/shiro/jndi/JndiObjectFactoryTest.java

Added: shiro/trunk/core/src/test/java/org/apache/shiro/jndi/JndiObjectFactoryTest.java
URL: http://svn.apache.org/viewvc/shiro/trunk/core/src/test/java/org/apache/shiro/jndi/JndiObjectFactoryTest.java?rev=1227045&view=auto
==============================================================================
--- shiro/trunk/core/src/test/java/org/apache/shiro/jndi/JndiObjectFactoryTest.java (added)
+++ shiro/trunk/core/src/test/java/org/apache/shiro/jndi/JndiObjectFactoryTest.java Wed Jan
 4 05:07:36 2012
@@ -0,0 +1,98 @@
+/*
+ * 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.shiro.jndi;
+
+import org.junit.Test;
+
+import javax.naming.NamingException;
+
+import static org.junit.Assert.assertEquals;
+
+/**
+ * This test makes the assumption that {@link JndiLocator} is tested elsewhere and only makes
an attempt to test the
+ * functionality added by {@link JndiObjectFactory}.
+ */
+public class JndiObjectFactoryTest {
+    @Test
+    public void testGetInstanceWithType() throws Exception {
+        final String name = "my/jndi/resource";
+        final String returnValue = "jndiString";
+        JndiObjectFactory<String> underTest = new JndiObjectFactory<String>()
{
+            @Override
+            protected Object lookup(String jndiName, Class requiredType) throws NamingException
{
+                assertEquals(name, jndiName);
+                assertEquals(String.class, requiredType);
+                return new String(returnValue);
+            }
+        };
+
+        underTest.setRequiredType(String.class);
+        underTest.setResourceName(name);
+
+        assertEquals(returnValue, underTest.getInstance());
+    }
+
+    @Test
+    public void testGetInstanceNoType() throws Exception {
+        final String name = "my/jndi/resource";
+        final String returnValue = "jndiString";
+        JndiObjectFactory<String> underTest = new JndiObjectFactory<String>()
{
+            @Override
+            protected Object lookup(String jndiName) throws NamingException {
+                assertEquals(name, jndiName);
+                return new String(returnValue);
+            }
+        };
+
+        underTest.setResourceName(name);
+
+        assertEquals(returnValue, underTest.getInstance());
+    }
+
+    @Test(expected = IllegalStateException.class)
+    public void testJndiLookupFailsWithType() throws Exception {
+        final String name = "my/jndi/resource";
+        JndiObjectFactory<String> underTest = new JndiObjectFactory<String>()
{
+            @Override
+            protected Object lookup(String jndiName, Class requiredType) throws NamingException
{
+                throw new NamingException("No resource named " + jndiName);
+            }
+        };
+
+        underTest.setResourceName(name);
+        underTest.setRequiredType(String.class);
+
+        underTest.getInstance();
+    }
+
+    @Test(expected = IllegalStateException.class)
+    public void testJndiLookupFailsNoType() throws Exception {
+        final String name = "my/jndi/resource";
+        JndiObjectFactory<String> underTest = new JndiObjectFactory<String>()
{
+            @Override
+            protected Object lookup(String jndiName) throws NamingException {
+                throw new NamingException("No resource named " + jndiName);
+            }
+        };
+
+        underTest.setResourceName(name);
+
+        underTest.getInstance();
+    }
+}



Mime
View raw message