Restrict Export-Package and convert test cases to Junit 4

git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@703589 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
rfeng 2008-10-10 22:28:22 +00:00
parent 267c37371a
commit 9134aecc4e
15 changed files with 196 additions and 142 deletions

View file

@ -66,7 +66,7 @@
<Bundle-Version>${tuscany.version}</Bundle-Version>
<Bundle-SymbolicName>org.apache.tuscany.sca.contribution.impl</Bundle-SymbolicName>
<Bundle-Description>${pom.name}</Bundle-Description>
<Export-Package>org.apache.tuscany.sca.contribution*</Export-Package>
<Export-Package></Export-Package>
</instructions>
</configuration>
</plugin>

View file

@ -18,14 +18,15 @@
*/
package org.apache.tuscany.sca.contribution.processor;
import static junit.framework.Assert.assertNotNull;
import java.io.File;
import java.net.URI;
import java.net.URL;
import java.util.List;
import junit.framework.TestCase;
import org.apache.tuscany.sca.contribution.processor.impl.FolderContributionProcessor;
import org.junit.Test;
/**
* Folder Package Processor test case
@ -33,9 +34,10 @@ import org.apache.tuscany.sca.contribution.processor.impl.FolderContributionProc
*
* @version $Rev$ $Date$
*/
public class FolderContributionPackageProcessorTestCase extends TestCase {
public class FolderContributionPackageProcessorTestCase {
private static final String FOLDER_CONTRIBUTION = ".";
@Test
public final void testProcessPackageArtifacts() throws Exception {
FolderContributionProcessor folderProcessor = new FolderContributionProcessor();
URL contributionURL = new File(FOLDER_CONTRIBUTION).toURL().toURI().toURL();

View file

@ -18,15 +18,16 @@
*/
package org.apache.tuscany.sca.contribution.processor;
import static junit.framework.Assert.assertNotNull;
import java.io.InputStream;
import java.net.URI;
import java.net.URL;
import java.util.List;
import junit.framework.TestCase;
import org.apache.tuscany.sca.contribution.processor.impl.JarContributionProcessor;
import org.apache.tuscany.sca.contribution.service.util.IOHelper;
import org.junit.Test;
/**
* JAR Package Processor test case
@ -35,9 +36,10 @@ import org.apache.tuscany.sca.contribution.service.util.IOHelper;
* @version $Rev$ $Date$
*/
public class JarContributionPackageProcessorTestCase extends TestCase {
public class JarContributionPackageProcessorTestCase {
private static final String JAR_CONTRIBUTION = "/repository/sample-calculator.jar";
@Test
public final void testProcessPackageArtifacts() throws Exception {
JarContributionProcessor jarProcessor = new JarContributionProcessor();

View file

@ -19,17 +19,18 @@
package org.apache.tuscany.sca.contribution.processor;
import static junit.framework.Assert.assertNotNull;
import java.net.URI;
import java.net.URL;
import junit.framework.TestCase;
import org.apache.tuscany.sca.contribution.resolver.ModelResolver;
import org.apache.tuscany.sca.contribution.service.ContributionReadException;
import org.apache.tuscany.sca.contribution.service.ContributionResolveException;
import org.apache.tuscany.sca.core.DefaultExtensionPointRegistry;
import org.apache.tuscany.sca.core.ExtensionPointRegistry;
import org.junit.BeforeClass;
import org.junit.Test;
/**
* URL Artifact Processor Extension Point test case
@ -37,24 +38,24 @@ import org.apache.tuscany.sca.core.ExtensionPointRegistry;
*
* @version $Rev$ $Date$
*/
public class URLartifactProcessorExtensionPointTestCase extends TestCase {
public class URLartifactProcessorExtensionPointTestCase {
private URLArtifactProcessorExtensionPoint artifactProcessors;
private static URLArtifactProcessorExtensionPoint artifactProcessors;
@Override
protected void setUp() throws Exception {
@BeforeClass
public static void setUp() throws Exception {
ExtensionPointRegistry extensionPoints = new DefaultExtensionPointRegistry();
artifactProcessors = new DefaultURLArtifactProcessorExtensionPoint(extensionPoints);
artifactProcessors.addArtifactProcessor(new FileTypeArtifactProcessor());
artifactProcessors.addArtifactProcessor(new FileNameArtifactProcessor());
}
@Test
public final void testFileTypeProcessor() {
assertNotNull(artifactProcessors.getProcessor(".m1"));
}
@Test
public final void testFileNameProcessor() {
assertNotNull(artifactProcessors.getProcessor("file.m2"));
@ -71,7 +72,7 @@ public class URLartifactProcessorExtensionPointTestCase extends TestCase {
private class M2 {
}
private class FileTypeArtifactProcessor implements URLArtifactProcessor<M1> {
private static class FileTypeArtifactProcessor implements URLArtifactProcessor<M1> {
public FileTypeArtifactProcessor() {
}
@ -91,7 +92,7 @@ public class URLartifactProcessorExtensionPointTestCase extends TestCase {
}
}
private class FileNameArtifactProcessor implements URLArtifactProcessor<M2> {
private static class FileNameArtifactProcessor implements URLArtifactProcessor<M2> {
public FileNameArtifactProcessor() {
}

View file

@ -19,28 +19,31 @@
package org.apache.tuscany.sca.contribution.resolver;
import junit.framework.TestCase;
import static junit.framework.Assert.assertTrue;
import org.apache.tuscany.sca.contribution.Artifact;
import org.apache.tuscany.sca.contribution.ContributionFactory;
import org.apache.tuscany.sca.contribution.DefaultContributionFactory;
import org.junit.Before;
import org.junit.Test;
/**
* Test the default model resolver implementation.
*
* @version $Rev$ $Date$
*/
public class DefaultModelResolverTestCase extends TestCase {
public class DefaultModelResolverTestCase {
private ModelResolver resolver;
private ContributionFactory factory;
@Override
protected void setUp() throws Exception {
@Before
public void setUp() throws Exception {
resolver = new DefaultModelResolver();
factory = new DefaultContributionFactory();
}
@Test
public void testResolved() {
Model a = new Model("a");
resolver.addModel(a);
@ -49,12 +52,14 @@ public class DefaultModelResolverTestCase extends TestCase {
assertTrue(x == a);
}
@Test
public void testUnresolved() {
Model x = new Model("a");
Model y = resolver.resolveModel(Model.class, x);
assertTrue(x == y);
}
@Test
public void testResolvedArtifact() {
Artifact artifact = factory.createArtifact();
artifact.setURI("foo/bar");

View file

@ -1,44 +1,46 @@
/*
* 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.
*/
/*
* 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.tuscany.sca.contribution.resolver;
import junit.framework.TestCase;
import static junit.framework.Assert.assertTrue;
import org.apache.tuscany.sca.contribution.Artifact;
import org.apache.tuscany.sca.contribution.ContributionFactory;
import org.apache.tuscany.sca.contribution.DefaultContributionFactory;
import org.apache.tuscany.sca.core.DefaultFactoryExtensionPoint;
import org.apache.tuscany.sca.core.FactoryExtensionPoint;
import org.junit.Before;
import org.junit.Test;
/**
* Test DefaultArtifactResolver.
*
* @version $Rev$ $Date$
*/
public class ExtensibleModelResolverTestCase extends TestCase {
public class ExtensibleModelResolverTestCase {
private ExtensibleModelResolver resolver;
private ContributionFactory factory;
@Override
protected void setUp() throws Exception {
@Before
public void setUp() throws Exception {
ModelResolverExtensionPoint resolvers = new DefaultModelResolverExtensionPoint();
resolvers.addResolver(Model.class, TestModelResolver.class);
@ -50,6 +52,7 @@ public class ExtensibleModelResolverTestCase extends TestCase {
factory = new DefaultContributionFactory();
}
@Test
public void testResolvedDefault() {
OtherModel a = new OtherModel("a");
resolver.addModel(a);
@ -58,6 +61,7 @@ public class ExtensibleModelResolverTestCase extends TestCase {
assertTrue(x == a);
}
@Test
public void testResolvedRegisteredClass() {
Model a = new Model("a");
resolver.addModel(a);
@ -66,18 +70,21 @@ public class ExtensibleModelResolverTestCase extends TestCase {
assertTrue(x == a);
}
@Test
public void testUnresolvedDefault() {
OtherModel x = new OtherModel("a");
OtherModel y = resolver.resolveModel(OtherModel.class, x);
assertTrue(x == y);
}
@Test
public void testUnresolved() {
Model x = new Model("a");
Model y = resolver.resolveModel(Model.class, x);
assertTrue(x == y);
}
@Test
public void testResolvedArtifact() {
Artifact artifact = factory.createArtifact();
artifact.setURI("foo/bar");

View file

@ -19,27 +19,33 @@
package org.apache.tuscany.sca.contribution.services;
import static junit.framework.Assert.assertEquals;
import static junit.framework.Assert.assertNotNull;
import static junit.framework.Assert.assertNull;
import java.io.File;
import java.io.InputStream;
import java.net.URL;
import javax.xml.stream.XMLInputFactory;
import junit.framework.TestCase;
import org.apache.tuscany.sca.contribution.service.impl.ContributionRepositoryImpl;
import org.apache.tuscany.sca.contribution.service.util.FileHelper;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
public class ContributionRepositoryTestCase extends TestCase {
private ContributionRepositoryImpl repository;
public class ContributionRepositoryTestCase {
private static ContributionRepositoryImpl repository;
@Override
protected void setUp() throws Exception {
@BeforeClass
public static void setUp() throws Exception {
// create repository (this should re-create the root directory)
this.repository = new ContributionRepositoryImpl("target/repository/", XMLInputFactory.newInstance(), null);
repository = new ContributionRepositoryImpl("target/repository/", XMLInputFactory.newInstance(), null);
repository.init();
}
@Test
public void testStore() throws Exception {
String resourceLocation = "/repository/sample-calculator.jar";
String contribution = "sample-calculator.jar";
@ -51,6 +57,7 @@ public class ContributionRepositoryTestCase extends TestCase {
assertNotNull(contributionURL);
}
@Test
public void testRemove() throws Exception {
String resourceLocation = "/repository/sample-calculator.jar";
String contribution = "sample-calculator.jar";
@ -63,6 +70,7 @@ public class ContributionRepositoryTestCase extends TestCase {
assertNull(contributionURL);
}
@Test
public void testList() throws Exception {
String resourceLocation = "/repository/sample-calculator.jar";
String contribution = "sample-calculator.jar";
@ -73,9 +81,8 @@ public class ContributionRepositoryTestCase extends TestCase {
assertEquals(1, repository.list().size());
}
@Override
protected void tearDown() throws Exception {
super.tearDown();
@AfterClass
public static void tearDown() throws Exception {
FileHelper.deleteDirectory(new File("target/repository"));
}
}

View file

@ -18,45 +18,52 @@
*/
package org.apache.tuscany.sca.contribution.services;
import java.net.URL;
import static junit.framework.Assert.assertEquals;
import static junit.framework.Assert.assertNull;
import junit.framework.TestCase;
import java.net.URL;
import org.apache.tuscany.sca.contribution.PackageType;
import org.apache.tuscany.sca.contribution.service.impl.PackageTypeDescriberImpl;
import org.junit.BeforeClass;
import org.junit.Test;
public class PackageTypeDescriberImplTestCase extends TestCase {
private PackageTypeDescriberImpl packageTypeDescriber;
public class PackageTypeDescriberImplTestCase {
private static PackageTypeDescriberImpl packageTypeDescriber;
@Test
public void testResolveArchivePackageType() throws Exception {
URL artifactURL = getClass().getResource("/deployables/sample-calculator.jar");
assertEquals(PackageType.JAR, this.packageTypeDescriber.getType(artifactURL, null));
}
@Test
public void testResolveFolderPackageType() throws Exception {
URL artifactURL = getClass().getResource("/deployables/");
assertEquals(PackageType.FOLDER, this.packageTypeDescriber.getType(artifactURL, null));
}
@Test
public void testResolveFolder2PackageType() throws Exception {
URL artifactURL = getClass().getResource("/deployables");
assertEquals(PackageType.FOLDER, this.packageTypeDescriber.getType(artifactURL, null));
}
@Test
public void testResolveUnknownPackageType() throws Exception {
URL artifactURL = getClass().getResource("/test.ext");
assertNull(this.packageTypeDescriber.getType(artifactURL, null));
}
@Test
public void testDefaultPackageType() throws Exception {
URL artifactURL = getClass().getResource("/test.ext");
assertEquals("application/vnd.tuscany.ext",
packageTypeDescriber.getType(artifactURL, "application/vnd.tuscany.ext"));
assertEquals("application/vnd.tuscany.ext", packageTypeDescriber.getType(artifactURL,
"application/vnd.tuscany.ext"));
}
@Override
protected void setUp() throws Exception {
@BeforeClass
public static void setUp() throws Exception {
packageTypeDescriber = new PackageTypeDescriberImpl();
}

View file

@ -66,7 +66,7 @@
<Bundle-Version>${tuscany.version}</Bundle-Version>
<Bundle-SymbolicName>org.apache.tuscany.sca.contribution.java</Bundle-SymbolicName>
<Bundle-Description>${pom.name}</Bundle-Description>
<Export-Package>org.apache.tuscany.sca.contribution.java*</Export-Package>
<Export-Package>org.apache.tuscany.sca.contribution.java</Export-Package>
<DynamicImport-Package>org.apache.tuscany.sca.contribution.osgi.impl</DynamicImport-Package>
</instructions>
</configuration>

View file

@ -19,7 +19,8 @@
package org.apache.tuscany.sca.contribution.java.impl;
import junit.framework.TestCase;
import static junit.framework.Assert.assertFalse;
import static junit.framework.Assert.assertTrue;
import org.apache.tuscany.sca.contribution.resolver.ClassReference;
import org.apache.tuscany.sca.contribution.resolver.ExtensibleModelResolver;
@ -27,17 +28,19 @@ import org.apache.tuscany.sca.contribution.resolver.ModelResolverExtensionPoint;
import org.apache.tuscany.sca.core.DefaultExtensionPointRegistry;
import org.apache.tuscany.sca.core.ExtensionPointRegistry;
import org.apache.tuscany.sca.core.FactoryExtensionPoint;
import org.junit.BeforeClass;
import org.junit.Test;
/**
* Test ClassReferenceArtifactResolver.
*
* @version $Rev: 560435 $ $Date: 2007-07-27 18:26:55 -0700 (Fri, 27 Jul 2007) $
*/
public class ClassReferenceArtifactResolverTestCase extends TestCase {
private ExtensibleModelResolver resolver;
public class ClassReferenceArtifactResolverTestCase {
private static ExtensibleModelResolver resolver;
@Override
protected void setUp() throws Exception {
@BeforeClass
public static void setUp() throws Exception {
ExtensionPointRegistry extensionPoints = new DefaultExtensionPointRegistry();
ModelResolverExtensionPoint resolvers = extensionPoints.getExtensionPoint(ModelResolverExtensionPoint.class);
@ -50,6 +53,7 @@ public class ClassReferenceArtifactResolverTestCase extends TestCase {
* Test ClassReference resolution
*
*/
@Test
public void testResolveClass() {
ClassReference ref = new ClassReference(getClass().getName());
ClassReference clazz = resolver.resolveModel(ClassReference.class, ref);
@ -61,6 +65,7 @@ public class ClassReferenceArtifactResolverTestCase extends TestCase {
* Test ClassReference resolution of inexistent class
*
*/
@Test
public void testUnresolvedClass() {
ClassReference ref = new ClassReference("NonExistentClass");
ClassReference clazz = resolver.resolveModel(ClassReference.class, ref);

View file

@ -35,7 +35,7 @@ import org.apache.tuscany.sca.core.DefaultExtensionPointRegistry;
import org.apache.tuscany.sca.core.ExtensionPointRegistry;
import org.apache.tuscany.sca.core.FactoryExtensionPoint;
import org.junit.Assert;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
@ -45,11 +45,11 @@ import org.junit.Test;
*/
public class ContributionClassLoaderTestCase {
private ContributionFactory contributionFactory;
private JavaImportExportFactory javaImportExportFactory;
private static ContributionFactory contributionFactory;
private static JavaImportExportFactory javaImportExportFactory;
@Before
public void setUp() throws Exception {
@BeforeClass
public static void setUp() throws Exception {
ExtensionPointRegistry extensionPoints = new DefaultExtensionPointRegistry();
FactoryExtensionPoint modelFactories = extensionPoints.getExtensionPoint(FactoryExtensionPoint.class);
contributionFactory = modelFactories.getFactory(ContributionFactory.class);

View file

@ -19,12 +19,15 @@
package org.apache.tuscany.sca.contribution.java.impl;
import static junit.framework.Assert.assertEquals;
import static junit.framework.Assert.assertNotNull;
import java.io.StringReader;
import javax.xml.stream.XMLInputFactory;
import javax.xml.stream.XMLStreamReader;
import junit.framework.TestCase;
import junit.framework.Assert;
import org.apache.tuscany.sca.contribution.java.JavaExport;
import org.apache.tuscany.sca.contribution.processor.ExtensibleStAXArtifactProcessor;
@ -37,13 +40,15 @@ import org.apache.tuscany.sca.monitor.DefaultMonitorFactory;
import org.apache.tuscany.sca.monitor.Monitor;
import org.apache.tuscany.sca.monitor.MonitorFactory;
import org.apache.tuscany.sca.monitor.Problem;
import org.junit.BeforeClass;
import org.junit.Test;
/**
* Test JavaExportProcessorTestCase
*
* @version $Rev$ $Date$
*/
public class JavaExportProcessorTestCase extends TestCase {
public class JavaExportProcessorTestCase {
private static final String VALID_XML =
"<?xml version=\"1.0\" encoding=\"ASCII\"?>"
@ -53,12 +58,12 @@ public class JavaExportProcessorTestCase extends TestCase {
"<?xml version=\"1.0\" encoding=\"ASCII\"?>"
+ "<export.java xmlns=\"http://www.osoa.org/xmlns/sca/1.0\"/>";
private XMLInputFactory inputFactory;
private StAXArtifactProcessor<Object> staxProcessor;
private Monitor monitor;
private static XMLInputFactory inputFactory;
private static StAXArtifactProcessor<Object> staxProcessor;
private static Monitor monitor;
@Override
protected void setUp() throws Exception {
@BeforeClass
public static void setUp() throws Exception {
ExtensionPointRegistry extensionPoints = new DefaultExtensionPointRegistry();
inputFactory = XMLInputFactory.newInstance();
// Create a monitor
@ -76,16 +81,18 @@ public class JavaExportProcessorTestCase extends TestCase {
* Test loading a valid export element from a contribution metadata stream
* @throws Exception
*/
@Test
public void testLoad() throws Exception {
XMLStreamReader reader = inputFactory.createXMLStreamReader(new StringReader(VALID_XML));
JavaExport javaExport = (JavaExport)staxProcessor.read(reader);
assertEquals("org.apache.tuscany.sca.contribution.java", javaExport.getPackage());
Assert.assertEquals("org.apache.tuscany.sca.contribution.java", javaExport.getPackage());
}
/**
* Test loading an INVALID export element from a contribution metadata stream
* @throws Exception
*/
@Test
public void testLoadInvalid() throws Exception {
XMLStreamReader reader = inputFactory.createXMLStreamReader(new StringReader(INVALID_XML));
/*try {

View file

@ -19,13 +19,14 @@
package org.apache.tuscany.sca.contribution.java.impl;
import static junit.framework.Assert.assertEquals;
import static junit.framework.Assert.assertNotNull;
import java.io.StringReader;
import javax.xml.stream.XMLInputFactory;
import javax.xml.stream.XMLStreamReader;
import junit.framework.TestCase;
import org.apache.tuscany.sca.contribution.java.JavaImport;
import org.apache.tuscany.sca.contribution.processor.ExtensibleStAXArtifactProcessor;
import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor;
@ -37,13 +38,15 @@ import org.apache.tuscany.sca.monitor.DefaultMonitorFactory;
import org.apache.tuscany.sca.monitor.Monitor;
import org.apache.tuscany.sca.monitor.MonitorFactory;
import org.apache.tuscany.sca.monitor.Problem;
import org.junit.BeforeClass;
import org.junit.Test;
/**
* Test JavaImportProcessorTestCase
*
* @version $Rev$ $Date$
*/
public class JavaImportProcessorTestCase extends TestCase {
public class JavaImportProcessorTestCase {
private static final String VALID_XML =
"<?xml version=\"1.0\" encoding=\"ASCII\"?>"
@ -53,12 +56,12 @@ public class JavaImportProcessorTestCase extends TestCase {
"<?xml version=\"1.0\" encoding=\"ASCII\"?>"
+ "<import.java xmlns=\"http://www.osoa.org/xmlns/sca/1.0\" xmlns:ns=\"http://ns\" location=\"sca://contributions/001\"/>";
private XMLInputFactory inputFactory;
private StAXArtifactProcessor<Object> staxProcessor;
private Monitor monitor;
private static XMLInputFactory inputFactory;
private static StAXArtifactProcessor<Object> staxProcessor;
private static Monitor monitor;
@Override
protected void setUp() throws Exception {
@BeforeClass
public static void setUp() throws Exception {
ExtensionPointRegistry extensionPoints = new DefaultExtensionPointRegistry();
inputFactory = XMLInputFactory.newInstance();
// Create a monitor
@ -76,6 +79,7 @@ public class JavaImportProcessorTestCase extends TestCase {
* Test loading a valid import element from a contribution metadata stream
* @throws Exception
*/
@Test
public void testLoad() throws Exception {
XMLStreamReader reader = inputFactory.createXMLStreamReader(new StringReader(VALID_XML));
JavaImport javaImport = (JavaImport)staxProcessor.read(reader);
@ -88,6 +92,7 @@ public class JavaImportProcessorTestCase extends TestCase {
* Test loading a INVALID import element from a contribution metadata stream
* @throws Exception
*/
@Test
public void testLoadInvalid() throws Exception {
XMLStreamReader reader = inputFactory.createXMLStreamReader(new StringReader(INVALID_XML));
/*try {

View file

@ -59,7 +59,13 @@
<Bundle-Version>${tuscany.version}</Bundle-Version>
<Bundle-SymbolicName>org.apache.tuscany.sca.contribution</Bundle-SymbolicName>
<Bundle-Description>${pom.name}</Bundle-Description>
<Export-Package>org.apache.tuscany.sca.contribution*</Export-Package>
<Export-Package>
org.apache.tuscany.sca.contribution,
org.apache.tuscany.sca.contribution.processor,
org.apache.tuscany.sca.contribution.resolver,
org.apache.tuscany.sca.contribution.scanner,
org.apache.tuscany.sca.contribution.service
</Export-Package>
</instructions>
</configuration>
</plugin>