[jboss-svn-commits] JBoss Common SVN: r3509 - in declarchive/trunk: impl-base/src/main/java/org/jboss/declarchive/impl/base and 1 other directories.
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Tue Sep 8 21:39:45 EDT 2009
Author: johnbailey
Date: 2009-09-08 21:39:45 -0400 (Tue, 08 Sep 2009)
New Revision: 3509
Added:
declarchive/trunk/api/src/main/java/org/jboss/declarchive/api/ArchiveFactory.java
declarchive/trunk/api/src/main/java/org/jboss/declarchive/api/EnterpriseArchiveFactory.java
declarchive/trunk/api/src/main/java/org/jboss/declarchive/api/FactoryUtil.java
declarchive/trunk/api/src/main/java/org/jboss/declarchive/api/JavaArchiveFactory.java
declarchive/trunk/api/src/main/java/org/jboss/declarchive/api/WebArchiveFactory.java
declarchive/trunk/impl-base/src/main/java/org/jboss/declarchive/impl/base/EnterpriseArchiveFactoryImpl.java
declarchive/trunk/impl-base/src/main/java/org/jboss/declarchive/impl/base/JavaArchiveFactoryImpl.java
declarchive/trunk/impl-base/src/main/java/org/jboss/declarchive/impl/base/WebArchiveFactoryImpl.java
declarchive/trunk/impl-base/src/test/java/org/jboss/declarchive/impl/base/unit/EnterpriseArchiveFactoryTestCase.java
declarchive/trunk/impl-base/src/test/java/org/jboss/declarchive/impl/base/unit/JavaArchiveFactoryTestCase.java
declarchive/trunk/impl-base/src/test/java/org/jboss/declarchive/impl/base/unit/WebArchiveFactoryTestCase.java
Log:
[TMPARCH-29] - Implemented Java, Web and Enterprise Archive factories
Added: declarchive/trunk/api/src/main/java/org/jboss/declarchive/api/ArchiveFactory.java
===================================================================
--- declarchive/trunk/api/src/main/java/org/jboss/declarchive/api/ArchiveFactory.java (rev 0)
+++ declarchive/trunk/api/src/main/java/org/jboss/declarchive/api/ArchiveFactory.java 2009-09-09 01:39:45 UTC (rev 3509)
@@ -0,0 +1,67 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2009, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * Licensed 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.jboss.declarchive.api;
+
+/**
+ * ArchiveFactory
+ *
+ * Template Factory used to create {@link Archive} instances.
+ *
+ * @author <a href="mailto:baileyje at gmail.com">John Bailey</a>
+ * @version $Revision: $
+ */
+abstract class ArchiveFactory<T extends Archive<T>>
+{
+
+ //-------------------------------------------------------------------------------------||
+ // Class Methods ----------------------------------------------------------------------||
+ //-------------------------------------------------------------------------------------||
+
+ /**
+ * Create an instance of an ArchiveFactory implementation
+ *
+ * @return ArchiveFactory instance
+ */
+ protected synchronized static <T extends Archive<T>, F extends ArchiveFactory<T>> F createInstance(
+ Class<F> factoryBaseType, String fqFactoryName)
+ {
+ try
+ {
+ // Create the instance
+ F instance = FactoryUtil.createInstance(fqFactoryName, factoryBaseType);
+
+ // Return the instance
+ return instance;
+ }
+ catch (Exception e)
+ {
+ throw new IllegalStateException("Make sure you have the impl classes on your runtime classpath", e);
+ }
+ }
+
+ //-------------------------------------------------------------------------------------||
+ // Contracts --------------------------------------------------------------------------||
+ //-------------------------------------------------------------------------------------||
+
+ /**
+ * Template create method for concrete implementations
+ *
+ * @param archiveName
+ * @return Archive instance
+ */
+ protected abstract T doCreate(String archiveName);
+}
Added: declarchive/trunk/api/src/main/java/org/jboss/declarchive/api/EnterpriseArchiveFactory.java
===================================================================
--- declarchive/trunk/api/src/main/java/org/jboss/declarchive/api/EnterpriseArchiveFactory.java (rev 0)
+++ declarchive/trunk/api/src/main/java/org/jboss/declarchive/api/EnterpriseArchiveFactory.java 2009-09-09 01:39:45 UTC (rev 3509)
@@ -0,0 +1,76 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2009, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * Licensed 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.jboss.declarchive.api;
+
+import org.jboss.declarchive.api.spec.EnterpriseArchive;
+
+/**
+ * EnterpriseArchiveFactory
+ *
+ * Factory used to create {@link EnterpriseArchive} instances.
+ *
+ * @author <a href="mailto:baileyje at gmail.com">John Bailey</a>
+ * @version $Revision: $
+ */
+public abstract class EnterpriseArchiveFactory extends ArchiveFactory<EnterpriseArchive>
+{
+
+ //-------------------------------------------------------------------------------------||
+ // Class Members ----------------------------------------------------------------------||
+ //-------------------------------------------------------------------------------------||
+
+ /**
+ * Implementation type as a FQN to avoid direct compile-time dependency
+ */
+ private static final String IMPL_TYPE = "org.jboss.declarchive.impl.base.EnterpriseArchiveFactoryImpl";
+
+ /**
+ * Instance of EnterpriseArchiveFactory implementation
+ */
+ private static EnterpriseArchiveFactory instance;
+
+ //-------------------------------------------------------------------------------------||
+ // Class Methods ----------------------------------------------------------------------||
+ //-------------------------------------------------------------------------------------||
+
+ /**
+ * Creates a {@link EnterpriseArchive} instance with the provided name.
+ *
+ * @param archiveName
+ * @return EnterpriseArchive instance
+ * @throws IllegalArgumentException if the archiveName is not present
+ */
+ public static EnterpriseArchive create(String archiveName)
+ {
+ return getInstance().doCreate(archiveName);
+ }
+
+ /**
+ * Return instance of the EnterpriseArchiveFactory
+ *
+ * @return
+ */
+ private static EnterpriseArchiveFactory getInstance()
+ {
+ if (instance == null)
+ {
+ instance = createInstance(EnterpriseArchiveFactory.class, IMPL_TYPE);
+ }
+ return instance;
+ }
+
+}
Added: declarchive/trunk/api/src/main/java/org/jboss/declarchive/api/FactoryUtil.java
===================================================================
--- declarchive/trunk/api/src/main/java/org/jboss/declarchive/api/FactoryUtil.java (rev 0)
+++ declarchive/trunk/api/src/main/java/org/jboss/declarchive/api/FactoryUtil.java 2009-09-09 01:39:45 UTC (rev 3509)
@@ -0,0 +1,106 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2009, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * Licensed 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.jboss.declarchive.api;
+
+import java.security.AccessController;
+import java.security.PrivilegedAction;
+import java.util.logging.Logger;
+
+/**
+ * FactoryUtil
+ *
+ * Package-private factory utilities
+ *
+ * @author <a href="mailto:andrew.rubinger at jboss.org">ALR</a>
+ * @version $Revision: $
+ */
+class FactoryUtil
+{
+
+ //-------------------------------------------------------------------------------------||
+ // Class Members ----------------------------------------------------------------------||
+ //-------------------------------------------------------------------------------------||
+
+ /**
+ * Logger
+ */
+ private static final Logger log = Logger.getLogger(FactoryUtil.class.getName());
+
+ //-------------------------------------------------------------------------------------||
+ // Constructor ------------------------------------------------------------------------||
+ //-------------------------------------------------------------------------------------||
+
+ /**
+ * Prohibit instantiation
+ */
+ private FactoryUtil()
+ {
+ throw new UnsupportedOperationException("No instances should be created; stateless utility class");
+ }
+
+ //-------------------------------------------------------------------------------------||
+ // Functional Methods -----------------------------------------------------------------||
+ //-------------------------------------------------------------------------------------||
+
+ /**
+ * Create an instance of the Class with the specified FQN, of the expected
+ * type
+ *
+ * @throws IllegalArgumentException If the specified type is not assignable to the instance
+ * of the class created from the specified class name, or if either argument is not
+ * supplied
+ */
+ static <T> T createInstance(final String className, final Class<T> type) throws IllegalArgumentException
+ {
+ // Precondition checks
+ if (className == null || className.length() == 0)
+ {
+ throw new IllegalArgumentException("className must be specified");
+ }
+ if (type == null)
+ {
+ throw new IllegalArgumentException("type must be specified");
+ }
+
+ return AccessController.doPrivileged(new PrivilegedAction<T>()
+ {
+ public T run()
+ {
+ try
+ {
+ final ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
+ final Class<?> clazz = Class.forName(className, false, classLoader);
+ final Object obj = clazz.newInstance();
+ try
+ {
+ return type.cast(obj);
+ }
+ catch (final ClassCastException cee)
+ {
+ throw new IllegalArgumentException("Specified type " + type.getName() + " is not assignable to "
+ + obj);
+ }
+ }
+ catch (Exception e)
+ {
+ throw new IllegalArgumentException("Unable to create implemenation: " + className, e);
+ }
+ }
+ });
+ }
+
+}
Added: declarchive/trunk/api/src/main/java/org/jboss/declarchive/api/JavaArchiveFactory.java
===================================================================
--- declarchive/trunk/api/src/main/java/org/jboss/declarchive/api/JavaArchiveFactory.java (rev 0)
+++ declarchive/trunk/api/src/main/java/org/jboss/declarchive/api/JavaArchiveFactory.java 2009-09-09 01:39:45 UTC (rev 3509)
@@ -0,0 +1,75 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2009, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * Licensed 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.jboss.declarchive.api;
+
+import org.jboss.declarchive.api.spec.JavaArchive;
+
+/**
+ * JavaArchiveFactory
+ *
+ * Factory used to create {@link JavaArchive} instances.
+ *
+ * @author <a href="mailto:baileyje at gmail.com">John Bailey</a>
+ * @version $Revision: $
+ */
+public abstract class JavaArchiveFactory extends ArchiveFactory<JavaArchive>
+{
+
+ //-------------------------------------------------------------------------------------||
+ // Class Members ----------------------------------------------------------------------||
+ //-------------------------------------------------------------------------------------||
+
+ /**
+ * Implementation type as a FQN to avoid direct compile-time dependency
+ */
+ private static final String IMPL_TYPE = "org.jboss.declarchive.impl.base.JavaArchiveFactoryImpl";
+
+ /**
+ * Instance of JavaArchiveFactory implementation
+ */
+ private static JavaArchiveFactory instance;
+
+ //-------------------------------------------------------------------------------------||
+ // Class Methods ----------------------------------------------------------------------||
+ //-------------------------------------------------------------------------------------||
+
+ /**
+ * Creates a {@link JavaArchive} instance with the provided name.
+ *
+ * @param archiveName
+ * @return JavaArchive
+ * @throws IllegalArgumentException if the archiveName is not present
+ */
+ public static JavaArchive create(String archiveName)
+ {
+ return getInstance().doCreate(archiveName);
+ }
+
+ /**
+ * Return instance of the JavaArchiveFactory
+ *
+ * @return
+ */
+ private static JavaArchiveFactory getInstance()
+ {
+ if (instance == null)
+ {
+ instance = createInstance(JavaArchiveFactory.class, IMPL_TYPE);
+ }
+ return instance;
+ }
+}
Added: declarchive/trunk/api/src/main/java/org/jboss/declarchive/api/WebArchiveFactory.java
===================================================================
--- declarchive/trunk/api/src/main/java/org/jboss/declarchive/api/WebArchiveFactory.java (rev 0)
+++ declarchive/trunk/api/src/main/java/org/jboss/declarchive/api/WebArchiveFactory.java 2009-09-09 01:39:45 UTC (rev 3509)
@@ -0,0 +1,75 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2009, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * Licensed 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.jboss.declarchive.api;
+
+import org.jboss.declarchive.api.spec.WebArchive;
+
+/**
+ * WebArchiveFactory
+ *
+ * Factory used to create {@link WebArchive} instances.
+ *
+ * @author <a href="mailto:baileyje at gmail.com">John Bailey</a>
+ * @version $Revision: $
+ */
+public abstract class WebArchiveFactory extends ArchiveFactory<WebArchive>
+{
+
+ //-------------------------------------------------------------------------------------||
+ // Class Members ----------------------------------------------------------------------||
+ //-------------------------------------------------------------------------------------||
+
+ /**
+ * Implementation type as a FQN to avoid direct compile-time dependency
+ */
+ private static final String IMPL_TYPE = "org.jboss.declarchive.impl.base.WebArchiveFactoryImpl";
+
+ /**
+ * Instance of WebArchiveFactory implementation
+ */
+ private static WebArchiveFactory instance;
+
+ //-------------------------------------------------------------------------------------||
+ // Class Methods ----------------------------------------------------------------------||
+ //-------------------------------------------------------------------------------------||
+
+ /**
+ * Creates a {@link WebArchive} instance with the provided name.
+ *
+ * @param archiveName
+ * @return WebArchive instance
+ * @throws IllegalArgumentException if the archiveName is not present
+ */
+ public static WebArchive create(String archiveName)
+ {
+ return getInstance().doCreate(archiveName);
+ }
+
+ /**
+ * Return instance of the WebArchiveFactory
+ *
+ * @return
+ */
+ private static WebArchiveFactory getInstance()
+ {
+ if (instance == null)
+ {
+ instance = createInstance(WebArchiveFactory.class, IMPL_TYPE);
+ }
+ return instance;
+ }
+}
Added: declarchive/trunk/impl-base/src/main/java/org/jboss/declarchive/impl/base/EnterpriseArchiveFactoryImpl.java
===================================================================
--- declarchive/trunk/impl-base/src/main/java/org/jboss/declarchive/impl/base/EnterpriseArchiveFactoryImpl.java (rev 0)
+++ declarchive/trunk/impl-base/src/main/java/org/jboss/declarchive/impl/base/EnterpriseArchiveFactoryImpl.java 2009-09-09 01:39:45 UTC (rev 3509)
@@ -0,0 +1,52 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2009, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * Licensed 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.jboss.declarchive.impl.base;
+
+import org.jboss.declarchive.api.EnterpriseArchiveFactory;
+import org.jboss.declarchive.api.spec.EnterpriseArchive;
+import org.jboss.declarchive.impl.base.spec.EnterpriseArchiveImpl;
+import org.jboss.declarchive.spi.MemoryMapArchive;
+
+/**
+ * EnterpriseArchiveFactoryImpl
+ *
+ * EnterpriseArchiveFactory implementation used to create {@link EnterpriseArchive} instances. Thread-safe.
+ *
+ * @author <a href="mailto:baileyje at gmail.com">John Bailey</a>
+ * @version $Revision: $
+ */
+public class EnterpriseArchiveFactoryImpl extends EnterpriseArchiveFactory
+{
+
+ /*
+ * {@inheritDoc}
+ * @see org.jboss.declarchive.api.EnterpriseArchiveFactory#doCreate(java.lang.String)
+ */
+ @Override
+ protected EnterpriseArchive doCreate(String archiveName)
+ {
+ // Create storage delegate
+ MemoryMapArchive memoryMapArchive = new MemoryMapArchiveImpl(archiveName);
+
+ // Create enterprise archive
+ EnterpriseArchive enterpriseArchive = new EnterpriseArchiveImpl(memoryMapArchive);
+
+ // Return archive
+ return enterpriseArchive;
+ }
+
+}
Added: declarchive/trunk/impl-base/src/main/java/org/jboss/declarchive/impl/base/JavaArchiveFactoryImpl.java
===================================================================
--- declarchive/trunk/impl-base/src/main/java/org/jboss/declarchive/impl/base/JavaArchiveFactoryImpl.java (rev 0)
+++ declarchive/trunk/impl-base/src/main/java/org/jboss/declarchive/impl/base/JavaArchiveFactoryImpl.java 2009-09-09 01:39:45 UTC (rev 3509)
@@ -0,0 +1,52 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2009, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * Licensed 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.jboss.declarchive.impl.base;
+
+import org.jboss.declarchive.api.JavaArchiveFactory;
+import org.jboss.declarchive.api.spec.JavaArchive;
+import org.jboss.declarchive.impl.base.spec.JavaArchiveImpl;
+import org.jboss.declarchive.spi.MemoryMapArchive;
+
+/**
+ * JavaArchiveFactoryImpl
+ *
+ * JavaArchiveFactory implementation used to create {@link JavaArchive} instances. Thread-safe.
+ *
+ * @author <a href="mailto:baileyje at gmail.com">John Bailey</a>
+ * @version $Revision: $
+ */
+public class JavaArchiveFactoryImpl extends JavaArchiveFactory
+{
+
+ /*
+ * {@inheritDoc}
+ * @see org.jboss.declarchive.api.JavaArchiveFactory#doCreate(java.lang.String)
+ */
+ @Override
+ protected JavaArchive doCreate(String archiveName)
+ {
+ // Create storage delegate
+ MemoryMapArchive memoryMapArchive = new MemoryMapArchiveImpl(archiveName);
+
+ // Create Java Archive
+ JavaArchive javaArchive = new JavaArchiveImpl(memoryMapArchive);
+
+ // Return archive
+ return javaArchive;
+ }
+
+}
Added: declarchive/trunk/impl-base/src/main/java/org/jboss/declarchive/impl/base/WebArchiveFactoryImpl.java
===================================================================
--- declarchive/trunk/impl-base/src/main/java/org/jboss/declarchive/impl/base/WebArchiveFactoryImpl.java (rev 0)
+++ declarchive/trunk/impl-base/src/main/java/org/jboss/declarchive/impl/base/WebArchiveFactoryImpl.java 2009-09-09 01:39:45 UTC (rev 3509)
@@ -0,0 +1,52 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2009, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * Licensed 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.jboss.declarchive.impl.base;
+
+import org.jboss.declarchive.api.WebArchiveFactory;
+import org.jboss.declarchive.api.spec.WebArchive;
+import org.jboss.declarchive.impl.base.spec.WebArchiveImpl;
+import org.jboss.declarchive.spi.MemoryMapArchive;
+
+/**
+ * WebArchiveFactoryImpl
+ *
+ * WebArchiveFactory implementation used to create {@link WebArchive} instances. Thread-safe.
+ *
+ * @author <a href="mailto:baileyje at gmail.com">John Bailey</a>
+ * @version $Revision: $
+ */
+public class WebArchiveFactoryImpl extends WebArchiveFactory
+{
+
+ /*
+ * {@inheritDoc}
+ * @see org.jboss.declarchive.api.WebArchiveFactory#doCreate(java.lang.String)
+ */
+ @Override
+ protected WebArchive doCreate(String archiveName)
+ {
+ // Create storage delegate
+ MemoryMapArchive memoryMapArchive = new MemoryMapArchiveImpl(archiveName);
+
+ // Create web archive
+ WebArchive webArchive = new WebArchiveImpl(memoryMapArchive);
+
+ // Return archive
+ return webArchive;
+ }
+
+}
Added: declarchive/trunk/impl-base/src/test/java/org/jboss/declarchive/impl/base/unit/EnterpriseArchiveFactoryTestCase.java
===================================================================
--- declarchive/trunk/impl-base/src/test/java/org/jboss/declarchive/impl/base/unit/EnterpriseArchiveFactoryTestCase.java (rev 0)
+++ declarchive/trunk/impl-base/src/test/java/org/jboss/declarchive/impl/base/unit/EnterpriseArchiveFactoryTestCase.java 2009-09-09 01:39:45 UTC (rev 3509)
@@ -0,0 +1,67 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2009, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * Licensed 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.jboss.declarchive.impl.base.unit;
+
+import junit.framework.Assert;
+
+import org.jboss.declarchive.api.EnterpriseArchiveFactory;
+import org.jboss.declarchive.api.spec.EnterpriseArchive;
+import org.junit.Test;
+
+/**
+ * EnterpriseArchiveFactoryTestCase
+ *
+ * TestCase to ensure the EnterpriseArchiveFactory functions correctly.
+ *
+ * @author <a href="mailto:baileyje at gmail.com">John Bailey</a>
+ * @version $Revision: $
+ */
+public class EnterpriseArchiveFactoryTestCase
+{
+
+ /**
+ * Test to ensure EnterpriseArchiveFactory returns a valid archive
+ * @throws Exception
+ */
+ @Test
+ public void testCreateArchive() throws Exception
+ {
+ String name = "test.ear";
+ EnterpriseArchive enterpriseArchive = EnterpriseArchiveFactory.create(name);
+ Assert.assertNotNull("Should return a valid enterprise archive", enterpriseArchive);
+ Assert.assertEquals("Should return the same name as factory arg", name, enterpriseArchive.getName());
+ }
+
+ /**
+ * Test to ensure EnterpriseArchiveFactory.create requires an archive name
+ * @throws Exception
+ */
+ @Test
+ public void testCreateArchiveRequiresName() throws Exception
+ {
+ try
+ {
+ EnterpriseArchiveFactory.create(null);
+ Assert.fail("Should have thrown IllegalArgumentException");
+ }
+ catch (IllegalArgumentException expected)
+ {
+ }
+
+ }
+
+}
Added: declarchive/trunk/impl-base/src/test/java/org/jboss/declarchive/impl/base/unit/JavaArchiveFactoryTestCase.java
===================================================================
--- declarchive/trunk/impl-base/src/test/java/org/jboss/declarchive/impl/base/unit/JavaArchiveFactoryTestCase.java (rev 0)
+++ declarchive/trunk/impl-base/src/test/java/org/jboss/declarchive/impl/base/unit/JavaArchiveFactoryTestCase.java 2009-09-09 01:39:45 UTC (rev 3509)
@@ -0,0 +1,67 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2009, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * Licensed 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.jboss.declarchive.impl.base.unit;
+
+import junit.framework.Assert;
+
+import org.jboss.declarchive.api.JavaArchiveFactory;
+import org.jboss.declarchive.api.spec.JavaArchive;
+import org.junit.Test;
+
+/**
+ * JavaArchiveFactoryTestCase
+ *
+ * TestCase to ensure the JavaArchiveFactory functions correctly.
+ *
+ * @author <a href="mailto:baileyje at gmail.com">John Bailey</a>
+ * @version $Revision: $
+ */
+public class JavaArchiveFactoryTestCase
+{
+
+ /**
+ * Test to ensure JavaArchiveFactory returns a valid archive
+ * @throws Exception
+ */
+ @Test
+ public void testCreateArchive() throws Exception
+ {
+ String name = "test.jar";
+ JavaArchive javaArchive = JavaArchiveFactory.create(name);
+ Assert.assertNotNull("Should return a valid java archive", javaArchive);
+ Assert.assertEquals("Should return the same name as factory arg", name, javaArchive.getName());
+ }
+
+ /**
+ * Test to ensure JavaArchiveFactory.create requires an archive name
+ * @throws Exception
+ */
+ @Test
+ public void testCreateArchiveRequiresName() throws Exception
+ {
+ try
+ {
+ JavaArchiveFactory.create(null);
+ Assert.fail("Should have thrown IllegalArgumentException");
+ }
+ catch (IllegalArgumentException expected)
+ {
+ }
+
+ }
+
+}
Added: declarchive/trunk/impl-base/src/test/java/org/jboss/declarchive/impl/base/unit/WebArchiveFactoryTestCase.java
===================================================================
--- declarchive/trunk/impl-base/src/test/java/org/jboss/declarchive/impl/base/unit/WebArchiveFactoryTestCase.java (rev 0)
+++ declarchive/trunk/impl-base/src/test/java/org/jboss/declarchive/impl/base/unit/WebArchiveFactoryTestCase.java 2009-09-09 01:39:45 UTC (rev 3509)
@@ -0,0 +1,67 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2009, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * Licensed 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.jboss.declarchive.impl.base.unit;
+
+import junit.framework.Assert;
+
+import org.jboss.declarchive.api.WebArchiveFactory;
+import org.jboss.declarchive.api.spec.WebArchive;
+import org.junit.Test;
+
+/**
+ * WebArchiveFactoryTestCase
+ *
+ * TestCase to ensure the WebArchiveFactory functions correctly.
+ *
+ * @author <a href="mailto:baileyje at gmail.com">John Bailey</a>
+ * @version $Revision: $
+ */
+public class WebArchiveFactoryTestCase
+{
+
+ /**
+ * Test to ensure WebArchiveFactory returns a valid archive
+ * @throws Exception
+ */
+ @Test
+ public void testCreateArchive() throws Exception
+ {
+ String name = "test.war";
+ WebArchive webArchive = WebArchiveFactory.create(name);
+ Assert.assertNotNull("Should return a valid web archive", webArchive);
+ Assert.assertEquals("Should return the same name as factory arg", name, webArchive.getName());
+ }
+
+ /**
+ * Test to ensure WebArchiveFactory.create requires an archive name
+ * @throws Exception
+ */
+ @Test
+ public void testCreateArchiveRequiresName() throws Exception
+ {
+ try
+ {
+ WebArchiveFactory.create(null);
+ Assert.fail("Should have thrown IllegalArgumentException");
+ }
+ catch (IllegalArgumentException expected)
+ {
+ }
+
+ }
+
+}
More information about the jboss-svn-commits
mailing list