You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tomee.apache.org by rm...@apache.org on 2012/10/31 14:20:41 UTC
svn commit: r1404128 - in /openejb/trunk/openejb/examples: ./ scala-basic/
scala-basic/src/ scala-basic/src/main/ scala-basic/src/main/resources/
scala-basic/src/main/resources/META-INF/ scala-basic/src/main/scala/
scala-basic/src/main/scala/org/ scala...
Author: rmannibucau
Date: Wed Oct 31 13:20:40 2012
New Revision: 1404128
URL: http://svn.apache.org/viewvc?rev=1404128&view=rev
Log:
adding a sample using scala
Added:
openejb/trunk/openejb/examples/scala-basic/
openejb/trunk/openejb/examples/scala-basic/build.sbt
openejb/trunk/openejb/examples/scala-basic/pom.xml
openejb/trunk/openejb/examples/scala-basic/src/
openejb/trunk/openejb/examples/scala-basic/src/main/
openejb/trunk/openejb/examples/scala-basic/src/main/resources/
openejb/trunk/openejb/examples/scala-basic/src/main/resources/META-INF/
openejb/trunk/openejb/examples/scala-basic/src/main/resources/META-INF/beans.xml
openejb/trunk/openejb/examples/scala-basic/src/main/scala/
openejb/trunk/openejb/examples/scala-basic/src/main/scala/org/
openejb/trunk/openejb/examples/scala-basic/src/main/scala/org/superbiz/
openejb/trunk/openejb/examples/scala-basic/src/main/scala/org/superbiz/GreetingService.scala
openejb/trunk/openejb/examples/scala-basic/src/test/
openejb/trunk/openejb/examples/scala-basic/src/test/scala/
openejb/trunk/openejb/examples/scala-basic/src/test/scala/org/
openejb/trunk/openejb/examples/scala-basic/src/test/scala/org/superbiz/
openejb/trunk/openejb/examples/scala-basic/src/test/scala/org/superbiz/GreetingServiceTest.scala
Modified:
openejb/trunk/openejb/examples/pom.xml
Modified: openejb/trunk/openejb/examples/pom.xml
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb/examples/pom.xml?rev=1404128&r1=1404127&r2=1404128&view=diff
==============================================================================
--- openejb/trunk/openejb/examples/pom.xml (original)
+++ openejb/trunk/openejb/examples/pom.xml Wed Oct 31 13:20:40 2012
@@ -103,6 +103,7 @@
<module>rest-on-ejb</module>
<module>rest-example</module>
<module>rest-example-with-application</module>
+ <module>scala-basic</module>
<module>schedule-expression</module>
<module>schedule-events</module>
<module>schedule-methods-meta</module>
Added: openejb/trunk/openejb/examples/scala-basic/build.sbt
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb/examples/scala-basic/build.sbt?rev=1404128&view=auto
==============================================================================
--- openejb/trunk/openejb/examples/scala-basic/build.sbt (added)
+++ openejb/trunk/openejb/examples/scala-basic/build.sbt Wed Oct 31 13:20:40 2012
@@ -0,0 +1,34 @@
+//
+// 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.
+//
+
+name := "scala-basic"
+
+version := "1.1-SNAPSHOT"
+
+scalaVersion := "2.9.1"
+
+resolvers ++= Seq(
+ "Local Maven Repository" at "file://" + Path.userHome.absolutePath + "/.m2/repository",
+ "Apache Snapshots" at "https://repository.apache.org/content/groups/snapshots/"
+)
+
+libraryDependencies ++= Seq(
+ "org.apache.openejb" % "javaee-api" % "6.0-4",
+ "org.apache.openejb" % "openejb-core" % "4.5.1-SNAPSHOT" % "test",
+ "org.scalatest" %% "scalatest" % "1.6.1" % "test"
+)
+
Added: openejb/trunk/openejb/examples/scala-basic/pom.xml
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb/examples/scala-basic/pom.xml?rev=1404128&view=auto
==============================================================================
--- openejb/trunk/openejb/examples/scala-basic/pom.xml (added)
+++ openejb/trunk/openejb/examples/scala-basic/pom.xml Wed Oct 31 13:20:40 2012
@@ -0,0 +1,148 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ 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.
+-->
+
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <groupId>org.superbiz</groupId>
+ <artifactId>scala-basic</artifactId>
+ <packaging>jar</packaging>
+ <version>1.1-SNAPSHOT</version>
+ <name>OpenEJB :: Examples :: Basic Scala</name>
+
+ <properties>
+ <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+ <scala.version>2.9.1</scala.version>
+ </properties>
+
+ <repositories>
+ <repository>
+ <id>apache-m2-snapshot</id>
+ <name>Apache Snapshot Repository</name>
+ <url>http://repository.apache.org/snapshots</url>
+ </repository>
+ </repositories>
+
+ <build>
+ <defaultGoal>install</defaultGoal>
+
+ <sourceDirectory>src/main/scala</sourceDirectory>
+ <testSourceDirectory>src/test/scala</testSourceDirectory>
+
+ <plugins>
+ <!-- compile scala sources -->
+ <plugin>
+ <groupId>net.alchim31.maven</groupId>
+ <artifactId>scala-maven-plugin</artifactId>
+ <version>3.1.0</version>
+ <executions>
+ <execution>
+ <goals>
+ <goal>compile</goal>
+ <goal>testCompile</goal>
+ </goals>
+ </execution>
+ </executions>
+ <configuration>
+ <scalaVersion>${scala.version}</scalaVersion>
+ </configuration>
+ </plugin>
+
+ <!-- disable surefire because we use scalatest -->
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-surefire-plugin</artifactId>
+ <version>2.12</version>
+ <configuration>
+ <skipTests>true</skipTests>
+ </configuration>
+ </plugin>
+ <!-- enable scalatest as a replacement for surefire -->
+ <plugin>
+ <groupId>org.scalatest</groupId>
+ <artifactId>scalatest-maven-plugin</artifactId>
+ <version>1.0-M2</version>
+ <configuration>
+ <reportsDirectory>${project.build.directory}/surefire-reports</reportsDirectory>
+ <junitxml>.</junitxml>
+ <filereports>TestSuite.txt</filereports>
+ </configuration>
+ <executions>
+ <execution>
+ <id>test</id>
+ <goals>
+ <goal>test</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
+ </plugins>
+ </build>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.openejb</groupId>
+ <artifactId>javaee-api</artifactId>
+ <version>6.0-4</version>
+ <scope>provided</scope>
+ </dependency>
+
+ <!-- scala dependencies for run and testing -->
+ <dependency>
+ <groupId>org.scala-lang</groupId>
+ <artifactId>scala-library</artifactId>
+ <version>${scala.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.scalatest</groupId>
+ <artifactId>scalatest_${scala.version}</artifactId>
+ <version>2.0.M4</version>
+ <scope>test</scope>
+ </dependency>
+
+ <!-- other "classical" dependencies -->
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <version>4.10</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.openejb</groupId>
+ <artifactId>openejb-core</artifactId>
+ <version>4.5.1-SNAPSHOT</version>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+
+ <!-- This section allows you to configure where to publish libraries for
+ sharing. It is not required and may be deleted. For more information see:
+ http://maven.apache.org/plugins/maven-deploy-plugin/ -->
+ <distributionManagement>
+ <repository>
+ <id>localhost</id>
+ <url>file://${basedir}/target/repo/</url>
+ </repository>
+ <snapshotRepository>
+ <id>localhost</id>
+ <url>file://${basedir}/target/snapshot-repo/</url>
+ </snapshotRepository>
+ </distributionManagement>
+</project>
Added: openejb/trunk/openejb/examples/scala-basic/src/main/resources/META-INF/beans.xml
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb/examples/scala-basic/src/main/resources/META-INF/beans.xml?rev=1404128&view=auto
==============================================================================
--- openejb/trunk/openejb/examples/scala-basic/src/main/resources/META-INF/beans.xml (added)
+++ openejb/trunk/openejb/examples/scala-basic/src/main/resources/META-INF/beans.xml Wed Oct 31 13:20:40 2012
@@ -0,0 +1,18 @@
+<!--
+
+ 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.
+-->
+<beans />
Added: openejb/trunk/openejb/examples/scala-basic/src/main/scala/org/superbiz/GreetingService.scala
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb/examples/scala-basic/src/main/scala/org/superbiz/GreetingService.scala?rev=1404128&view=auto
==============================================================================
--- openejb/trunk/openejb/examples/scala-basic/src/main/scala/org/superbiz/GreetingService.scala (added)
+++ openejb/trunk/openejb/examples/scala-basic/src/main/scala/org/superbiz/GreetingService.scala Wed Oct 31 13:20:40 2012
@@ -0,0 +1,36 @@
+/**
+ * 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.superbiz
+
+import javax.ejb.{Singleton, LocalBean, Lock, LockType}
+
+object GreetingService {
+ val DefaultName = "Scala"
+}
+
+@LocalBean
+@Singleton
+@Lock(LockType.READ)
+class GreetingService {
+ def hi(name: String = GreetingService.DefaultName) = {
+ if (name != null) {
+ "hi " + name
+ } else {
+ "hi " + GreetingService.DefaultName
+ }
+ }
+}
Added: openejb/trunk/openejb/examples/scala-basic/src/test/scala/org/superbiz/GreetingServiceTest.scala
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb/examples/scala-basic/src/test/scala/org/superbiz/GreetingServiceTest.scala?rev=1404128&view=auto
==============================================================================
--- openejb/trunk/openejb/examples/scala-basic/src/test/scala/org/superbiz/GreetingServiceTest.scala (added)
+++ openejb/trunk/openejb/examples/scala-basic/src/test/scala/org/superbiz/GreetingServiceTest.scala Wed Oct 31 13:20:40 2012
@@ -0,0 +1,63 @@
+/**
+ * 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.superbiz
+
+import org.scalatest._
+
+import javax.ejb.embeddable.EJBContainer
+import javax.inject.Inject
+
+class GreetingServiceTest extends FunSuite with BeforeAndAfterAll with BeforeAndAfterEach {
+ @Inject
+ private var service: GreetingService = null
+
+ test ("Hi scala") {
+ val message = service hi "scala"
+ assert (message == "hi scala")
+ }
+
+ test ("Default Hi") {
+ val message = service.hi()
+ assert (message == "hi Scala")
+ }
+
+ test ("Hi null") {
+ val message = service.hi(null)
+ assert (message == "hi Scala") // when called with null we use default name
+ }
+
+ /***************************************************************/
+ /** the OpenEJB Hook to be able to inject beans in this class **/
+ /** kind of internal of this test class, "hidden" being last **/
+ /***************************************************************/
+
+ private var container: EJBContainer = null
+
+ override def beforeAll () {
+ container = EJBContainer.createEJBContainer ()
+ }
+
+ override def beforeEach () {
+ container.getContext().bind ("inject", this)
+ }
+
+ override def afterAll () {
+ if (container != null) {
+ container.close()
+ }
+ }
+}