[jboss-svn-commits] JBoss Common SVN: r3929 - in arquillian/trunk: demo/src/test/java/com/acme/cdi and 5 other directories.

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Tue Jan 12 07:56:11 EST 2010


Author: aslak
Date: 2010-01-12 07:56:10 -0500 (Tue, 12 Jan 2010)
New Revision: 3929

Added:
   arquillian/trunk/demo-testng/src/main/java/com/acme/cdi/
   arquillian/trunk/demo-testng/src/main/java/com/acme/cdi/translate/
   arquillian/trunk/demo-testng/src/main/java/com/acme/cdi/translate/NorwegianTranslator.java
   arquillian/trunk/demo-testng/src/main/java/com/acme/cdi/translate/SentenceParser.java
   arquillian/trunk/demo-testng/src/main/java/com/acme/cdi/translate/TextTranslator.java
   arquillian/trunk/demo-testng/src/main/java/com/acme/cdi/translate/TranslateController.java
   arquillian/trunk/demo-testng/src/main/java/com/acme/cdi/translate/Translator.java
   arquillian/trunk/demo-testng/src/test/java/com/acme/cdi/translate/
   arquillian/trunk/demo-testng/src/test/java/com/acme/cdi/translate/TranslateTestCase.java
Removed:
   arquillian/trunk/demo/src/main/java/com/acme/cdi/translate/
   arquillian/trunk/demo/src/test/java/com/acme/cdi/translate/
Log:
ARQ-35 ARQ-54 Moved @SessionScoped testcase to TestNG demo. Only TestNG can guarantee the test method execution order

Added: arquillian/trunk/demo-testng/src/main/java/com/acme/cdi/translate/NorwegianTranslator.java
===================================================================
--- arquillian/trunk/demo-testng/src/main/java/com/acme/cdi/translate/NorwegianTranslator.java	                        (rev 0)
+++ arquillian/trunk/demo-testng/src/main/java/com/acme/cdi/translate/NorwegianTranslator.java	2010-01-12 12:56:10 UTC (rev 3929)
@@ -0,0 +1,28 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2009, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * Licensed 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 com.acme.cdi.translate;
+
+import javax.ejb.Stateless;
+
+ at Stateless
+public class NorwegianTranslator implements Translator {
+
+	@Override
+	public String translate(String sentence) {
+		return "hei";
+	}
+}

Added: arquillian/trunk/demo-testng/src/main/java/com/acme/cdi/translate/SentenceParser.java
===================================================================
--- arquillian/trunk/demo-testng/src/main/java/com/acme/cdi/translate/SentenceParser.java	                        (rev 0)
+++ arquillian/trunk/demo-testng/src/main/java/com/acme/cdi/translate/SentenceParser.java	2010-01-12 12:56:10 UTC (rev 3929)
@@ -0,0 +1,31 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2009, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * Licensed 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 com.acme.cdi.translate;
+
+import java.io.Serializable;
+import java.util.Arrays;
+import java.util.List;
+
+public class SentenceParser implements Serializable {
+
+	private static final long serialVersionUID = 1L;
+
+	public List<String> parse(String text) 
+	{
+		return Arrays.asList(text.split(" "));
+	}
+}
\ No newline at end of file

Added: arquillian/trunk/demo-testng/src/main/java/com/acme/cdi/translate/TextTranslator.java
===================================================================
--- arquillian/trunk/demo-testng/src/main/java/com/acme/cdi/translate/TextTranslator.java	                        (rev 0)
+++ arquillian/trunk/demo-testng/src/main/java/com/acme/cdi/translate/TextTranslator.java	2010-01-12 12:56:10 UTC (rev 3929)
@@ -0,0 +1,44 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2009, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * Licensed 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 com.acme.cdi.translate;
+
+import java.io.Serializable;
+
+import javax.inject.Inject;
+
+public class TextTranslator implements Serializable {
+
+	private static final long serialVersionUID = 1L;
+
+	private SentenceParser sentenceParser;
+	private Translator sentenceTranslator;
+
+	@Inject
+	TextTranslator(SentenceParser sentenceParser, Translator sentenceTranslator) {
+		this.sentenceParser = sentenceParser;
+		this.sentenceTranslator = sentenceTranslator;
+	}
+
+	public String translate(String text) {
+
+		StringBuilder sb = new StringBuilder();
+		for (String sentence : sentenceParser.parse(text)) {
+			sb.append(sentenceTranslator.translate(sentence));
+		}
+		return sb.toString();
+	}
+}
\ No newline at end of file

Added: arquillian/trunk/demo-testng/src/main/java/com/acme/cdi/translate/TranslateController.java
===================================================================
--- arquillian/trunk/demo-testng/src/main/java/com/acme/cdi/translate/TranslateController.java	                        (rev 0)
+++ arquillian/trunk/demo-testng/src/main/java/com/acme/cdi/translate/TranslateController.java	2010-01-12 12:56:10 UTC (rev 3929)
@@ -0,0 +1,54 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2009, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * Licensed 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 com.acme.cdi.translate;
+
+import java.io.Serializable;
+
+import javax.enterprise.context.SessionScoped;
+import javax.inject.Inject;
+import javax.inject.Named;
+
+ at Named
+ at SessionScoped
+public class TranslateController implements Serializable {
+
+	private static final long serialVersionUID = 1L;
+
+	@Inject
+	TextTranslator textTranslator;
+
+	private String inputText;
+
+	private String translation;
+
+	// JSF action method, perhaps
+	public void translate() {
+		translation = textTranslator.translate(inputText);
+	}
+
+	public String getInputText() {
+		return inputText;
+	}
+
+	public void setInputText(String text) {
+		this.inputText = text;
+	}
+
+	public String getTranslation() {
+		return translation;
+	}
+}
\ No newline at end of file

Added: arquillian/trunk/demo-testng/src/main/java/com/acme/cdi/translate/Translator.java
===================================================================
--- arquillian/trunk/demo-testng/src/main/java/com/acme/cdi/translate/Translator.java	                        (rev 0)
+++ arquillian/trunk/demo-testng/src/main/java/com/acme/cdi/translate/Translator.java	2010-01-12 12:56:10 UTC (rev 3929)
@@ -0,0 +1,26 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2009, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * Licensed 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 com.acme.cdi.translate;
+
+import javax.ejb.Local;
+
+ at Local
+public interface Translator {
+
+   public String translate(String sentence);
+
+}
\ No newline at end of file

Added: arquillian/trunk/demo-testng/src/test/java/com/acme/cdi/translate/TranslateTestCase.java
===================================================================
--- arquillian/trunk/demo-testng/src/test/java/com/acme/cdi/translate/TranslateTestCase.java	                        (rev 0)
+++ arquillian/trunk/demo-testng/src/test/java/com/acme/cdi/translate/TranslateTestCase.java	2010-01-12 12:56:10 UTC (rev 3929)
@@ -0,0 +1,61 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2009, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * Licensed 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 com.acme.cdi.translate;
+
+import javax.inject.Inject;
+
+import org.jboss.arquillian.api.Deployment;
+import org.jboss.arquillian.testng.Arquillian;
+import org.jboss.shrinkwrap.api.Archives;
+import org.jboss.shrinkwrap.api.Paths;
+import org.jboss.shrinkwrap.api.spec.JavaArchive;
+import org.jboss.shrinkwrap.impl.base.asset.ByteArrayAsset;
+import org.testng.Assert;
+import org.testng.annotations.Test;
+
+public class TranslateTestCase extends Arquillian {
+
+	@Deployment
+	public static JavaArchive createDeployment() {
+		return Archives.create("test.jar", JavaArchive.class)
+				.addPackage(
+						TranslateController.class.getPackage())
+				.addManifestResource(
+						new ByteArrayAsset("<beans/>".getBytes()),
+						Paths.create("beans.xml"));
+	}
+	
+	@Inject TranslateController controller;
+
+	@Test
+	public void shouldSetInputText() throws Exception 
+	{
+		controller.setInputText("hi");
+	}
+	
+	@Test(dependsOnMethods = "shouldSetInputText")
+	public void shouldTranslate() throws Exception 
+	{
+		controller.translate();
+	}
+	
+	@Test(dependsOnMethods = "shouldTranslate")
+	public void shouldVerify() throws Exception 
+	{
+		Assert.assertEquals(controller.getTranslation(), "hei");
+	}
+}



More information about the jboss-svn-commits mailing list