Micha Kops avatar Micha Kops committed 2cf0d76

initial import

Comments (0)

Files changed (5)

+<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/xsd/maven-4.0.0.xsd">
+	<modelVersion>4.0.0</modelVersion>
+	<groupId>com.hascode.tutorial</groupId>
+	<artifactId>ejb-tutorial</artifactId>
+	<version>0.0.1</version>
+	<packaging>ejb</packaging>
+	<name>hasCode.com ejb-tutorial EJB</name>
+
+	<properties>
+		<endorsed.dir>${project.build.directory}/endorsed</endorsed.dir>
+		<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+	</properties>
+
+	<dependencies>
+		<dependency>
+			<groupId>org.glassfish.extras</groupId>
+			<artifactId>glassfish-embedded-all</artifactId>
+			<version>3.0</version>
+			<scope>test</scope>
+		</dependency>
+		<dependency>
+			<groupId>junit</groupId>
+			<artifactId>junit</artifactId>
+			<version>4.8.1</version>
+			<scope>test</scope>
+		</dependency>
+		<dependency>
+			<groupId>javax</groupId>
+			<artifactId>javaee-api</artifactId>
+			<version>6.0</version>
+			<scope>provided</scope>
+		</dependency>
+	</dependencies>
+
+	<build>
+		<plugins>
+			<plugin>
+				<groupId>org.apache.maven.plugins</groupId>
+				<artifactId>maven-compiler-plugin</artifactId>
+				<version>2.3.2</version>
+				<configuration>
+					<source>1.6</source>
+					<target>1.6</target>
+					<compilerArguments>
+						<endorseddirs>${endorsed.dir}</endorseddirs>
+					</compilerArguments>
+				</configuration>
+			</plugin>
+			<plugin>
+				<groupId>org.apache.maven.plugins</groupId>
+				<artifactId>maven-ejb-plugin</artifactId>
+				<version>2.3</version>
+				<configuration>
+					<ejbVersion>3.1</ejbVersion>
+				</configuration>
+			</plugin>
+			<plugin>
+				<groupId>org.apache.maven.plugins</groupId>
+				<artifactId>maven-dependency-plugin</artifactId>
+				<version>2.1</version>
+				<executions>
+					<execution>
+						<phase>validate</phase>
+						<goals>
+							<goal>copy</goal>
+						</goals>
+						<configuration>
+							<outputDirectory>${endorsed.dir}</outputDirectory>
+							<silent>true</silent>
+							<artifactItems>
+								<artifactItem>
+									<groupId>javax</groupId>
+									<artifactId>javaee-endorsed-api</artifactId>
+									<version>6.0</version>
+									<type>jar</type>
+								</artifactItem>
+							</artifactItems>
+						</configuration>
+					</execution>
+				</executions>
+			</plugin>
+		</plugins>
+		<finalName>ejb-tutorial</finalName>
+	</build>
+	
+	<repositories>
+		<repository>
+			<id>maven2-repository.dev.java.net</id>
+			<name>Java.net Repository for Maven</name>
+			<url>http://download.java.net/maven/2/</url>
+			<layout>default</layout>
+		</repository>
+		<repository>
+			<id>maven2-repository.dev.java.net.glassfish</id>
+			<name>Java.net Repository for Maven</name>
+			<url>http://download.java.net/maven/glassfish/</url>
+		</repository>
+	</repositories>
+</project>

src/main/java/com/hascode/tutorial/ejb_tutorial/bean/UserBean.java

+package com.hascode.tutorial.ejb_tutorial.bean;
+
+public class UserBean {
+	private Long	id;
+
+	private String	firstName;
+
+	private String	lastName;
+
+	public Long getId() {
+		return id;
+	}
+
+	public void setId(Long id) {
+		this.id = id;
+	}
+
+	public String getFirstName() {
+		return firstName;
+	}
+
+	public void setFirstName(String firstName) {
+		this.firstName = firstName;
+	}
+
+	public String getLastName() {
+		return lastName;
+	}
+
+	public void setLastName(String lastName) {
+		this.lastName = lastName;
+	}
+}

src/main/java/com/hascode/tutorial/ejb_tutorial/bean/UserEJB.java

+package com.hascode.tutorial.ejb_tutorial.bean;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.ejb.Stateless;
+
+@Stateless
+public class UserEJB {
+	public List<UserBean> findAll() {
+		List<UserBean> users = new ArrayList<UserBean>();
+		UserBean user = new UserBean();
+		user.setFirstName("Alfred");
+		user.setLastName("Newman");
+		user.setId(1l);
+
+		UserBean anotherUser = new UserBean();
+		anotherUser.setFirstName("Albert");
+		anotherUser.setLastName("Einstein");
+		anotherUser.setId(2l);
+
+		users.add(user);
+		users.add(anotherUser);
+		return users;
+	}
+}

src/main/resources/META-INF/MANIFEST.MF

+Manifest-Version: 1.0
+

src/test/java/com/hascode/tutorial/ejb_tutorial/bean/UserEJBTest.java

+package com.hascode.tutorial.ejb_tutorial.bean;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+
+import java.util.List;
+
+import javax.ejb.embeddable.EJBContainer;
+import javax.naming.Context;
+import javax.naming.NamingException;
+
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+public class UserEJBTest {
+	private static EJBContainer	ejbContainer;
+	private static Context		ctx;
+
+	@BeforeClass
+	public static void setUp() {
+		ejbContainer = EJBContainer.createEJBContainer();
+		ctx = ejbContainer.getContext();
+	}
+
+	@AfterClass
+	public static void tearDown() {
+		ejbContainer.close();
+	}
+
+	@Test
+	public void testFindAll() {
+		try {
+			UserEJB userEJB = (UserEJB) ctx.lookup("java:global/classes/UserEJB!com.hascode.tutorial.ejb_tutorial.bean.UserEJB");
+			assertNotNull(userEJB);
+			List<UserBean> users = userEJB.findAll();
+			assertNotNull(users);
+			assertEquals(2, users.size());
+		} catch (NamingException e) {
+			throw new AssertionError(e);
+		}
+	}
+}
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.