From a221c8cbf542c88fd6d8842264f2cec0c663b325 Mon Sep 17 00:00:00 2001 From: Matej Novotny Date: Wed, 19 Jul 2017 12:25:14 +0200 Subject: [PATCH] WELD-2409 Remove JSF stress test from integration test suite. --- .../org/jboss/weld/tests/stress/Game.java | 101 ------------ .../jboss/weld/tests/stress/Generator.java | 31 ---- .../weld/tests/stress/JsfStressTest.java | 146 ------------------ .../jboss/weld/tests/stress/MaxNumber.java | 21 --- .../org/jboss/weld/tests/stress/Random.java | 21 --- .../jboss/weld/tests/stress/faces-config.xml | 11 -- .../org/jboss/weld/tests/stress/home.xhtml | 34 ---- .../org/jboss/weld/tests/stress/index.html | 5 - .../jboss/weld/tests/stress/template.xhtml | 33 ---- .../org/jboss/weld/tests/stress/web.xml | 31 ---- 10 files changed, 434 deletions(-) delete mode 100644 tests-arquillian/src/test/java/org/jboss/weld/tests/stress/Game.java delete mode 100644 tests-arquillian/src/test/java/org/jboss/weld/tests/stress/Generator.java delete mode 100644 tests-arquillian/src/test/java/org/jboss/weld/tests/stress/JsfStressTest.java delete mode 100644 tests-arquillian/src/test/java/org/jboss/weld/tests/stress/MaxNumber.java delete mode 100644 tests-arquillian/src/test/java/org/jboss/weld/tests/stress/Random.java delete mode 100644 tests-arquillian/src/test/resources/org/jboss/weld/tests/stress/faces-config.xml delete mode 100644 tests-arquillian/src/test/resources/org/jboss/weld/tests/stress/home.xhtml delete mode 100644 tests-arquillian/src/test/resources/org/jboss/weld/tests/stress/index.html delete mode 100644 tests-arquillian/src/test/resources/org/jboss/weld/tests/stress/template.xhtml delete mode 100644 tests-arquillian/src/test/resources/org/jboss/weld/tests/stress/web.xml diff --git a/tests-arquillian/src/test/java/org/jboss/weld/tests/stress/Game.java b/tests-arquillian/src/test/java/org/jboss/weld/tests/stress/Game.java deleted file mode 100644 index 976ff1806fb..00000000000 --- a/tests-arquillian/src/test/java/org/jboss/weld/tests/stress/Game.java +++ /dev/null @@ -1,101 +0,0 @@ -package org.jboss.weld.tests.stress; - -import javax.annotation.PostConstruct; -import javax.enterprise.context.SessionScoped; -import javax.enterprise.inject.Instance; -import javax.faces.application.FacesMessage; -import javax.faces.component.UIComponent; -import javax.faces.component.UIInput; -import javax.faces.context.FacesContext; -import javax.inject.Inject; -import javax.inject.Named; -import java.io.Serializable; - -@Named -@SessionScoped -public class Game implements Serializable { - /** - * - */ - private static final long serialVersionUID = 991300443278089016L; - - private int number; - - private int guess; - private int smallest; - - @Inject - @MaxNumber - private int maxNumber; - - private int biggest; - private int remainingGuesses; - - @Inject - @Random - Instance randomNumber; - - public Game() { - } - - public int getNumber() { - return number; - } - - public int getGuess() { - return guess; - } - - public void setGuess(int guess) { - this.guess = guess; - } - - public int getSmallest() { - return smallest; - } - - public int getBiggest() { - return biggest; - } - - public int getRemainingGuesses() { - return remainingGuesses; - } - - public void check() { - if (guess > number) { - biggest = guess - 1; - } else if (guess < number) { - smallest = guess + 1; - } else if (guess == number) { - FacesContext.getCurrentInstance().addMessage(null, new FacesMessage("Correct!")); - } - remainingGuesses--; - } - - @PostConstruct - public void reset() { - this.smallest = 0; - this.guess = -1; - this.remainingGuesses = 10; - this.biggest = maxNumber; - this.number = randomNumber.get(); - } - - public void validateNumberRange(FacesContext context, UIComponent toValidate, Object value) { - if (remainingGuesses <= 0) { - FacesMessage message = new FacesMessage("No guesses left!"); - context.addMessage(toValidate.getClientId(context), message); - ((UIInput) toValidate).setValid(false); - return; - } - int input = (Integer) value; - - if (input < smallest || input > biggest) { - ((UIInput) toValidate).setValid(false); - - FacesMessage message = new FacesMessage("Invalid guess"); - context.addMessage(toValidate.getClientId(context), message); - } - } -} diff --git a/tests-arquillian/src/test/java/org/jboss/weld/tests/stress/Generator.java b/tests-arquillian/src/test/java/org/jboss/weld/tests/stress/Generator.java deleted file mode 100644 index 07523f58891..00000000000 --- a/tests-arquillian/src/test/java/org/jboss/weld/tests/stress/Generator.java +++ /dev/null @@ -1,31 +0,0 @@ -package org.jboss.weld.tests.stress; - - -import javax.enterprise.context.ApplicationScoped; -import javax.enterprise.inject.Produces; -import java.io.Serializable; - -@ApplicationScoped -public class Generator implements Serializable { - private static final long serialVersionUID = -7213673465118041882L; - - private java.util.Random random = new java.util.Random(System.currentTimeMillis()); - - private int maxNumber = 100; - - java.util.Random getRandom() { - return random; - } - - @Produces - @Random - int next() { - return getRandom().nextInt(maxNumber); - } - - @Produces - @MaxNumber - int getMaxNumber() { - return maxNumber; - } -} diff --git a/tests-arquillian/src/test/java/org/jboss/weld/tests/stress/JsfStressTest.java b/tests-arquillian/src/test/java/org/jboss/weld/tests/stress/JsfStressTest.java deleted file mode 100644 index e1df8d8f913..00000000000 --- a/tests-arquillian/src/test/java/org/jboss/weld/tests/stress/JsfStressTest.java +++ /dev/null @@ -1,146 +0,0 @@ -/* - * JBoss, Home of Professional Open Source - * Copyright 2010, Red Hat, Inc. and/or its affiliates, 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 org.jboss.weld.tests.stress; - -import com.gargoylesoftware.htmlunit.WebClient; -import com.gargoylesoftware.htmlunit.html.HtmlInput; -import com.gargoylesoftware.htmlunit.html.HtmlPage; -import com.gargoylesoftware.htmlunit.html.HtmlSpan; -import com.gargoylesoftware.htmlunit.html.HtmlSubmitInput; -import org.databene.contiperf.PerfTest; -import org.databene.contiperf.junit.ContiPerfRule; -import org.jboss.arquillian.container.test.api.Deployment; -import org.jboss.arquillian.junit.Arquillian; -import org.jboss.arquillian.test.api.ArquillianResource; -import org.jboss.shrinkwrap.api.ShrinkWrap; -import org.jboss.shrinkwrap.api.asset.EmptyAsset; -import org.jboss.shrinkwrap.api.spec.WebArchive; -import org.jboss.weld.test.util.Utils; -import org.jboss.weld.tests.category.Integration; -import org.junit.Assert; -import org.junit.Rule; -import org.junit.Test; -import org.junit.experimental.categories.Category; -import org.junit.runner.RunWith; - -import java.io.IOException; -import java.net.URL; - -/** - * Stress test of basically the JSF NumberGuess game example. - * - * @author David Allen - */ -@Category(Integration.class) -@RunWith(Arquillian.class) -public class JsfStressTest { - protected final String MAIN_PAGE = "/home.jsf"; - protected final String GUESS_MESSAGES = "numberGuess:messages"; - - protected final String GUESS_FIELD = "numberGuess:inputGuess"; - protected final String GUESS_SUBMIT = "numberGuess:guessButton"; - protected final String GUESS_RESET = "numberGuess:restartButton"; - protected final String GUESS_SMALLEST = "numberGuess:smallest"; - protected final String GUESS_BIGGEST = "numberGuess:biggest"; - - protected String WIN_MSG = "Correct!"; - protected String LOSE_MSG = "No guesses left!"; - - @ArquillianResource - private URL url; - - @Rule - public ContiPerfRule i = new ContiPerfRule(); - - @Deployment(testable = false) - public static WebArchive createDeployment() { - return ShrinkWrap.create(WebArchive.class, Utils.getDeploymentNameAsHash(JsfStressTest.class, Utils.ARCHIVE_TYPE.WAR)) - .addClasses(Game.class, Generator.class, MaxNumber.class, Random.class) - .addAsWebInfResource(JsfStressTest.class.getPackage(), "web.xml", "web.xml") - .addAsWebInfResource(JsfStressTest.class.getPackage(), "faces-config.xml", "faces-config.xml") - .addAsWebResource(JsfStressTest.class.getPackage(), "home.xhtml", "home.xhtml") - .addAsWebResource(JsfStressTest.class.getPackage(), "index.html", "index.html") - .addAsWebResource(JsfStressTest.class.getPackage(), "template.xhtml", "template.xhtml") - .addAsWebInfResource(EmptyAsset.INSTANCE, "beans.xml"); - } - - @Test - @PerfTest(invocations = 500) - public void testJsfApp() throws Exception { - WebClient client = new WebClient(); - client.setThrowExceptionOnFailingStatusCode(false); - HtmlPage page = client.getPage(getPath(MAIN_PAGE)); - - int min; - int max; - int guess; - int i = 0; - - while (isOnGuessPage(page)) { - Assert.assertTrue("Game should not be longer than 10 guesses", i <= 10); - - min = Integer.parseInt(getSpanValue(page, GUESS_SMALLEST)); - max = Integer.parseInt(getSpanValue(page, GUESS_BIGGEST)); - guess = min + ((max - min) / 2); - page = enterGuess(page, guess); - i++; - } - reset(page); - Assert.assertTrue("Win page expected after playing smart.", isOnWinPage(page)); - - client.closeAllWindows(); - } - - protected void reset(HtmlPage page) throws IOException { - ((HtmlSubmitInput) page.getElementById(GUESS_RESET)).click(); - } - - protected HtmlPage enterGuess(HtmlPage page, int guess) throws IOException { - ((HtmlInput) page.getElementById(GUESS_FIELD)).setValueAttribute(String.valueOf(guess)); - HtmlSubmitInput submitButton = (HtmlSubmitInput) page.getElementById(GUESS_SUBMIT); - if (submitButton.isDisabled()) { - throw new RuntimeException("Guess button disabled on page: " + page.asText()); - } - return submitButton.click(); - } - - protected boolean isOnGuessPage(HtmlPage page) { - return !(isOnWinPage(page) || isOnLosePage(page)); - } - - protected boolean isOnWinPage(HtmlPage page) { - String text = page.getElementById(GUESS_MESSAGES).asText(); - return WIN_MSG.equals(text); - } - - protected boolean isOnLosePage(HtmlPage page) { - String text = page.getElementById(GUESS_MESSAGES).asText(); - return LOSE_MSG.equals(text); - } - - protected String getSpanValue(HtmlPage page, String fieldId) { - HtmlSpan span = (HtmlSpan) page.getElementById(fieldId); - return span.asText(); - } - - protected String getPath(String viewId) { - return url + viewId; - } - - -} diff --git a/tests-arquillian/src/test/java/org/jboss/weld/tests/stress/MaxNumber.java b/tests-arquillian/src/test/java/org/jboss/weld/tests/stress/MaxNumber.java deleted file mode 100644 index 465e0f57aec..00000000000 --- a/tests-arquillian/src/test/java/org/jboss/weld/tests/stress/MaxNumber.java +++ /dev/null @@ -1,21 +0,0 @@ -package org.jboss.weld.tests.stress; - - -import javax.inject.Qualifier; -import java.lang.annotation.Documented; -import java.lang.annotation.Retention; -import java.lang.annotation.Target; - -import static java.lang.annotation.ElementType.FIELD; -import static java.lang.annotation.ElementType.METHOD; -import static java.lang.annotation.ElementType.PARAMETER; -import static java.lang.annotation.ElementType.TYPE; -import static java.lang.annotation.RetentionPolicy.RUNTIME; - -@Target({TYPE, METHOD, PARAMETER, FIELD}) -@Retention(RUNTIME) -@Documented -@Qualifier -public @interface MaxNumber { - -} diff --git a/tests-arquillian/src/test/java/org/jboss/weld/tests/stress/Random.java b/tests-arquillian/src/test/java/org/jboss/weld/tests/stress/Random.java deleted file mode 100644 index 954d819a908..00000000000 --- a/tests-arquillian/src/test/java/org/jboss/weld/tests/stress/Random.java +++ /dev/null @@ -1,21 +0,0 @@ -package org.jboss.weld.tests.stress; - - -import javax.inject.Qualifier; -import java.lang.annotation.Documented; -import java.lang.annotation.Retention; -import java.lang.annotation.Target; - -import static java.lang.annotation.ElementType.FIELD; -import static java.lang.annotation.ElementType.METHOD; -import static java.lang.annotation.ElementType.PARAMETER; -import static java.lang.annotation.ElementType.TYPE; -import static java.lang.annotation.RetentionPolicy.RUNTIME; - -@Target({TYPE, METHOD, PARAMETER, FIELD}) -@Retention(RUNTIME) -@Documented -@Qualifier -public @interface Random { - -} diff --git a/tests-arquillian/src/test/resources/org/jboss/weld/tests/stress/faces-config.xml b/tests-arquillian/src/test/resources/org/jboss/weld/tests/stress/faces-config.xml deleted file mode 100644 index 896e8346608..00000000000 --- a/tests-arquillian/src/test/resources/org/jboss/weld/tests/stress/faces-config.xml +++ /dev/null @@ -1,11 +0,0 @@ - - - - numberguess - - diff --git a/tests-arquillian/src/test/resources/org/jboss/weld/tests/stress/home.xhtml b/tests-arquillian/src/test/resources/org/jboss/weld/tests/stress/home.xhtml deleted file mode 100644 index 6438294fc5f..00000000000 --- a/tests-arquillian/src/test/resources/org/jboss/weld/tests/stress/home.xhtml +++ /dev/null @@ -1,34 +0,0 @@ - - - - - -

Guess a number...

- -
- - - -
- -
- I'm thinking of a number between #{game.smallest} and #{game.biggest}. You have #{game.remainingGuesses} guesses remaining. -
- -
- Your guess: - - -
-
- -
-
-
-
- diff --git a/tests-arquillian/src/test/resources/org/jboss/weld/tests/stress/index.html b/tests-arquillian/src/test/resources/org/jboss/weld/tests/stress/index.html deleted file mode 100644 index 473be2f071f..00000000000 --- a/tests-arquillian/src/test/resources/org/jboss/weld/tests/stress/index.html +++ /dev/null @@ -1,5 +0,0 @@ - - - - - \ No newline at end of file diff --git a/tests-arquillian/src/test/resources/org/jboss/weld/tests/stress/template.xhtml b/tests-arquillian/src/test/resources/org/jboss/weld/tests/stress/template.xhtml deleted file mode 100644 index 0cfa166098b..00000000000 --- a/tests-arquillian/src/test/resources/org/jboss/weld/tests/stress/template.xhtml +++ /dev/null @@ -1,33 +0,0 @@ - - - - - - Numberguess - - - - - -
- - - - -
- -
- -
-
- - - - diff --git a/tests-arquillian/src/test/resources/org/jboss/weld/tests/stress/web.xml b/tests-arquillian/src/test/resources/org/jboss/weld/tests/stress/web.xml deleted file mode 100644 index a87c743110d..00000000000 --- a/tests-arquillian/src/test/resources/org/jboss/weld/tests/stress/web.xml +++ /dev/null @@ -1,31 +0,0 @@ - - - - Web Beans Numberguess example - - - javax.faces.DEFAULT_SUFFIX - .xhtml - - - - Faces Servlet - javax.faces.webapp.FacesServlet - 1 - - - - Faces Servlet - *.jsf - - - - 10 - - -