diff options
author | lresende <lresende@13f79535-47bb-0310-9956-ffa450edef68> | 2010-09-06 16:49:51 +0000 |
---|---|---|
committer | lresende <lresende@13f79535-47bb-0310-9956-ffa450edef68> | 2010-09-06 16:49:51 +0000 |
commit | 1f63bc03e8cf8dd761a51e9f83c18b25654adbf4 (patch) | |
tree | 71509850b1bfaf44c4593cbf6afa5dd2d6dd153c /sca-java-2.x/trunk/modules/contribution-resource/src/test/java/org/apache/tuscany/sca/contribution/resource/impl/ResourceExportProcessorTestCase.java | |
parent | 4957d288168a5620b52537f754a529007514f811 (diff) |
Porting support to import/export resources from 1.x
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@993091 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'sca-java-2.x/trunk/modules/contribution-resource/src/test/java/org/apache/tuscany/sca/contribution/resource/impl/ResourceExportProcessorTestCase.java')
-rw-r--r-- | sca-java-2.x/trunk/modules/contribution-resource/src/test/java/org/apache/tuscany/sca/contribution/resource/impl/ResourceExportProcessorTestCase.java | 62 |
1 files changed, 30 insertions, 32 deletions
diff --git a/sca-java-2.x/trunk/modules/contribution-resource/src/test/java/org/apache/tuscany/sca/contribution/resource/impl/ResourceExportProcessorTestCase.java b/sca-java-2.x/trunk/modules/contribution-resource/src/test/java/org/apache/tuscany/sca/contribution/resource/impl/ResourceExportProcessorTestCase.java index ea44cb506b..98bd460add 100644 --- a/sca-java-2.x/trunk/modules/contribution-resource/src/test/java/org/apache/tuscany/sca/contribution/resource/impl/ResourceExportProcessorTestCase.java +++ b/sca-java-2.x/trunk/modules/contribution-resource/src/test/java/org/apache/tuscany/sca/contribution/resource/impl/ResourceExportProcessorTestCase.java @@ -6,81 +6,78 @@ * 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. + * under the License. */ package org.apache.tuscany.sca.contribution.resource.impl; +import static org.junit.Assert.assertEquals; +import static org.junit.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.processor.ExtensibleStAXArtifactProcessor; +import org.apache.tuscany.sca.contribution.processor.ProcessorContext; import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor; import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessorExtensionPoint; import org.apache.tuscany.sca.contribution.resource.ResourceExport; import org.apache.tuscany.sca.core.DefaultExtensionPointRegistry; import org.apache.tuscany.sca.core.ExtensionPointRegistry; -import org.apache.tuscany.sca.core.UtilityExtensionPoint; import org.apache.tuscany.sca.monitor.Monitor; -import org.apache.tuscany.sca.monitor.MonitorFactory; import org.apache.tuscany.sca.monitor.Problem; -import org.apache.tuscany.sca.monitor.impl.DefaultMonitorFactoryImpl; -import org.apache.tuscany.sca.monitor.impl.DefaultMonitorImpl; +import org.junit.BeforeClass; +import org.junit.Test; /** * Test NamespaceExportProcessorTestCase - * + * * @version $Rev$ $Date$ */ -public class ResourceExportProcessorTestCase extends TestCase { +public class ResourceExportProcessorTestCase { private static final String VALID_XML = - "<?xml version=\"1.0\" encoding=\"ASCII\"?>" - + "<export.resource xmlns=\"http://www.osoa.org/xmlns/sca/1.0\" xmlns:ns=\"http://ns\" uri=\"helloworld/HelloWorldService.componentType\"/>"; + "<?xml version=\"1.0\" encoding=\"ASCII\"?>" + + "<export.resource xmlns=\"http://tuscany.apache.org/xmlns/sca/1.1\" xmlns:ns=\"http://ns\" uri=\"helloworld/HelloWorldService.componentType\"/>"; private static final String INVALID_XML = - "<?xml version=\"1.0\" encoding=\"ASCII\"?>" - + "<export.resource xmlns=\"http://www.osoa.org/xmlns/sca/1.0\" xmlns:ns=\"http://ns\"/>"; + "<?xml version=\"1.0\" encoding=\"ASCII\"?>" + + "<export.resource xmlns=\"http://tuscany.apache.org/xmlns/sca/1.1\" xmlns:ns=\"http://ns\"/>"; - private XMLInputFactory inputFactory; - private StAXArtifactProcessor<Object> staxProcessor; - private Monitor monitor; + private static XMLInputFactory inputFactory; + private static StAXArtifactProcessor<Object> staxProcessor; + private static Monitor monitor; + private static ProcessorContext context; - @Override - protected void setUp() throws Exception { + @BeforeClass + public static void setUp() throws Exception { ExtensionPointRegistry extensionPoints = new DefaultExtensionPointRegistry(); + context = new ProcessorContext(extensionPoints); + monitor = context.getMonitor(); inputFactory = XMLInputFactory.newInstance(); - // Create a monitor - UtilityExtensionPoint utilities = extensionPoints.getExtensionPoint(UtilityExtensionPoint.class); - MonitorFactory monitorFactory = new DefaultMonitorFactoryImpl(); - if (monitorFactory != null) { - monitor = monitorFactory.createMonitor(); - utilities.addUtility(monitorFactory); - } + StAXArtifactProcessorExtensionPoint staxProcessors = extensionPoints.getExtensionPoint(StAXArtifactProcessorExtensionPoint.class); - staxProcessor = new ExtensibleStAXArtifactProcessor(staxProcessors, inputFactory, null, null); + staxProcessor = new ExtensibleStAXArtifactProcessor(staxProcessors, inputFactory, null); } /** * 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)); - ResourceExport resourceExport = (ResourceExport)staxProcessor.read(reader); + ResourceExport resourceExport = (ResourceExport)staxProcessor.read(reader, context); assertEquals("helloworld/HelloWorldService.componentType", resourceExport.getURI()); } @@ -88,6 +85,7 @@ public class ResourceExportProcessorTestCase extends TestCase { * 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 { @@ -96,9 +94,9 @@ public class ResourceExportProcessorTestCase extends TestCase { } catch (ContributionReadException e) { assertTrue(true); }*/ - staxProcessor.read(reader); - Problem problem = ((DefaultMonitorImpl)monitor).getLastLoggedProblem(); + staxProcessor.read(reader, context); + Problem problem = monitor.getLastProblem(); assertNotNull(problem); assertEquals("AttributeURIMissing", problem.getMessageId()); - } + } } |