diff options
author | lresende <lresende@13f79535-47bb-0310-9956-ffa450edef68> | 2009-11-13 01:42:27 +0000 |
---|---|---|
committer | lresende <lresende@13f79535-47bb-0310-9956-ffa450edef68> | 2009-11-13 01:42:27 +0000 |
commit | 3c7c4a749baafcf375f4785a7668d3a25c9063e3 (patch) | |
tree | a66b8b031c5dc6c7744f44b44b6bcd371bd0b8df /sca-java-1.x/trunk/itest/workspace-manager/src/test/java/org/apache/tuscany/sca/workspace | |
parent | eb03ff672236cddf65533f39b83ddd5e2984a2bb (diff) |
Moving 1.x trunk
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@835700 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'sca-java-1.x/trunk/itest/workspace-manager/src/test/java/org/apache/tuscany/sca/workspace')
-rw-r--r-- | sca-java-1.x/trunk/itest/workspace-manager/src/test/java/org/apache/tuscany/sca/workspace/manager/test/WorkspaceManagerTestCase.java | 146 |
1 files changed, 146 insertions, 0 deletions
diff --git a/sca-java-1.x/trunk/itest/workspace-manager/src/test/java/org/apache/tuscany/sca/workspace/manager/test/WorkspaceManagerTestCase.java b/sca-java-1.x/trunk/itest/workspace-manager/src/test/java/org/apache/tuscany/sca/workspace/manager/test/WorkspaceManagerTestCase.java new file mode 100644 index 0000000000..efd6d11b8e --- /dev/null +++ b/sca-java-1.x/trunk/itest/workspace-manager/src/test/java/org/apache/tuscany/sca/workspace/manager/test/WorkspaceManagerTestCase.java @@ -0,0 +1,146 @@ +/* + * 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.workspace.manager.test; + +import static org.junit.Assert.assertEquals; + + +import org.apache.tuscany.sca.artifact.xyz.XYZ; +import org.apache.tuscany.sca.artifact.xyz.XYZModelResolver; +import org.apache.tuscany.sca.artifact.xyz.XYZProcessor; +import org.apache.tuscany.sca.contribution.Contribution; +import org.apache.tuscany.sca.contribution.ModelFactoryExtensionPoint; +import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessorExtensionPoint; +import org.apache.tuscany.sca.contribution.processor.URLArtifactProcessorExtensionPoint; +import org.apache.tuscany.sca.contribution.processor.ValidationSchemaExtensionPoint; +import org.apache.tuscany.sca.contribution.resolver.ModelResolverExtensionPoint; +import org.apache.tuscany.sca.core.ExtensionPointRegistry; +import org.apache.tuscany.sca.core.UtilityExtensionPoint; +import org.apache.tuscany.sca.implementation.xyz.ImplementationXYZFactoryImpl; +import org.apache.tuscany.sca.implementation.xyz.ImplementationXYZProcessor; +import org.apache.tuscany.sca.imprt.xyz.DefaultImportExportXYZFactory; +import org.apache.tuscany.sca.imprt.xyz.ExportXYZProcessor; +import org.apache.tuscany.sca.imprt.xyz.ImportXYZProcessor; +import org.apache.tuscany.sca.monitor.Monitor; +import org.apache.tuscany.sca.monitor.MonitorFactory; +import org.apache.tuscany.sca.workspace.Workspace; +import org.apache.tuscany.sca.workspace.manager.WorkspaceManager; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + + +public class WorkspaceManagerTestCase { + + private WorkspaceManager workspaceManager; + + @Before + public void init() { + workspaceManager = WorkspaceManager.newInstance(); + addExtensions(workspaceManager); + workspaceManager.start(); + } + + @Test + public void testHelloWorldCreate() throws Exception { + Workspace workspace = loadWorkspace(workspaceManager); + assertEquals(1, workspace.getContributions().get(0).getDeployables().size()); + } + + private void addExtensions(WorkspaceManager workspaceManager) { + try { + System.out.println("Add extensions"); + ExtensionPointRegistry registry = workspaceManager.getRegistry(); + + // get monitor + UtilityExtensionPoint utilities = + registry.getExtensionPoint(UtilityExtensionPoint.class); + MonitorFactory monitorFactory = utilities.getUtility(MonitorFactory.class); + Monitor monitor = monitorFactory.createMonitor(); + + // create validation schema + // are schema required + ValidationSchemaExtensionPoint schemas = + registry.getExtensionPoint(ValidationSchemaExtensionPoint.class); + schemas.addSchema(WorkspaceManagerTestCase.class.getClassLoader().getResource("implementation-xyz.xsd").toString()); + schemas.addSchema(WorkspaceManagerTestCase.class.getClassLoader().getResource("import-xyz.xsd").toString()); + + // create model factories + ModelFactoryExtensionPoint modelFactories = + registry.getExtensionPoint(ModelFactoryExtensionPoint.class); + + modelFactories.addFactory(new ImplementationXYZFactoryImpl()); + modelFactories.addFactory(new DefaultImportExportXYZFactory()); + + // Create URL artifact processors + URLArtifactProcessorExtensionPoint urlProcessors = + registry.getExtensionPoint(URLArtifactProcessorExtensionPoint.class); + + urlProcessors.addArtifactProcessor(new XYZProcessor(modelFactories, monitor)); + + // Create stax artifact processors + StAXArtifactProcessorExtensionPoint artifactProcessors = + registry.getExtensionPoint(StAXArtifactProcessorExtensionPoint.class); + + artifactProcessors.addArtifactProcessor(new ImplementationXYZProcessor(modelFactories, + monitor)); + artifactProcessors.addArtifactProcessor(new ImportXYZProcessor(modelFactories, + monitor)); + artifactProcessors.addArtifactProcessor(new ExportXYZProcessor(modelFactories, + monitor)); + + // create model resolvers + ModelResolverExtensionPoint modelResolvers = + registry.getExtensionPoint(ModelResolverExtensionPoint.class); + + modelResolvers.addResolver(XYZ.class, XYZModelResolver.class); + + } catch (Exception ex) { + ex.printStackTrace(); + } + } + + private Workspace loadWorkspace(WorkspaceManager workspaceManager){ + try { + System.out.println("Process contribution"); + + Workspace workspace = workspaceManager.createWorkspace(); + + Contribution contribution = workspaceManager.readContribution("contrib2", "./target/classes/contrib2"); + workspaceManager.addContributionToWorkspace(workspace, contribution); + + contribution = workspaceManager.readContribution("contrib1", "./target/classes/contrib1"); + workspaceManager.addContributionToWorkspace(workspace, contribution); + + workspaceManager.resolveWorkspace(workspace); + + return workspace; + + } catch (Exception ex) { + ex.printStackTrace(); + } + + return null; + } + + @After + public void end() { + workspaceManager.stop(); + } +} |