glassfish
  1. glassfish
  2. GLASSFISH-20099

[Fighterfish Test]adding a method in WebAppBundle class for GLASSFISH-18836 test

    Details

    • Type: Bug Bug
    • Status: Resolved
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 4.0_b82_EE7MS7
    • Fix Version/s: 4.0_b83
    • Component/s: OSGi-JavaEE
    • Labels:
      None

      Description

      needint to add a method in WAB class for GLASSFISH-18836 test.

      Otherwise, T1_SamplesTest will failed because of jaxrs sample.

      [#|2013-03-29T15:17:43.486+0900|SEVERE|glassfish 4.0|org.ops4j.pax.exam.junit.JUnit4TestRunner|_ThreadID=1;_ThreadName=main;_TimeMillis=1364537863486;_LevelValue=1000;ClassName=org.ops4j.pax.exam.junit.JUnit4TestRunner$3;MethodName=evaluate;|
      Exception
      org.ops4j.pax.exam.TestContainerException: [test(org.glassfish.fighterfish.test.it.SingleTest): Server returned HTTP response code: 415 for URL: http://localhost:8080/simplejaxrs/register?name=admin&password=admin]
      at org.ops4j.pax.exam.invoker.junit.internal.JUnitProbeInvoker.invokeViaJUnit(JUnitProbeInvoker.java:112)
      at org.ops4j.pax.exam.invoker.junit.internal.JUnitProbeInvoker.findAndInvoke(JUnitProbeInvoker.java:89)
      at org.ops4j.pax.exam.invoker.junit.internal.JUnitProbeInvoker.call(JUnitProbeInvoker.java:72)
      at org.ops4j.pax.exam.nat.internal.NativeTestContainer.call(NativeTestContainer.java:86)
      at org.ops4j.pax.exam.spi.reactors.EagerSingleStagedReactor.invoke(EagerSingleStagedReactor.java:85)
      at org.ops4j.pax.exam.junit.JUnit4TestRunner$3.evaluate(JUnit4TestRunner.java:289)
      at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:76)
      at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)
      at org.junit.runners.ParentRunner$3.run(ParentRunner.java:193)
      at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:52)
      at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:191)
      at org.junit.runners.ParentRunner.access$000(ParentRunner.java:42)
      at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:184)
      at org.junit.runners.ParentRunner.run(ParentRunner.java:236)
      at org.ops4j.pax.exam.junit.JUnit4TestRunner.run(JUnit4TestRunner.java:87)
      at org.apache.maven.surefire.junit4.JUnit4TestSet.execute(JUnit4TestSet.java:53)
      at org.apache.maven.surefire.junit4.JUnit4Provider.executeTestSet(JUnit4Provider.java:119)
      at org.apache.maven.surefire.junit4.JUnit4Provider.invoke(JUnit4Provider.java:101)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      at java.lang.reflect.Method.invoke(Method.java:601)
      at org.apache.maven.surefire.booter.ProviderFactory$ClassLoaderProxy.invoke(ProviderFactory.java:103)
      at $Proxy0.invoke(Unknown Source)
      at org.apache.maven.surefire.booter.SurefireStarter.invokeProvider(SurefireStarter.java:150)
      at org.apache.maven.surefire.booter.SurefireStarter.runSuitesInProcess(SurefireStarter.java:91)
      at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:69)
      Caused by: java.io.IOException: Server returned HTTP response code: 415 for URL: http://localhost:8080/simplejaxrs/register?name=admin&password=admin
      at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1615)
      at org.glassfish.fighterfish.test.util.WebAppBundle.getHttpResponse(WebAppBundle.java:199)
      at org.glassfish.fighterfish.test.util.WebAppBundle.getHttpPostResponse(WebAppBundle.java:171)
      at org.glassfish.fighterfish.test.it.SingleTest.test(SingleTest.java:109)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      at java.lang.reflect.Method.invoke(Method.java:601)
      at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44)
      at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
      at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41)
      at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
      at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:263)
      at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:69)
      at org.ops4j.pax.exam.invoker.junit.internal.ContainerTestRunner.runChild(ContainerTestRunner.java:58)
      at org.ops4j.pax.exam.invoker.junit.internal.ContainerTestRunner.runChild(ContainerTestRunner.java:32)
      at org.junit.runners.ParentRunner$3.run(ParentRunner.java:231)
      at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:60)
      at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:229)
      at org.junit.runners.ParentRunner.access$000(ParentRunner.java:50)
      at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:222)
      at org.junit.runners.ParentRunner.run(ParentRunner.java:292)
      at org.junit.runner.JUnitCore.run(JUnitCore.java:157)
      at org.junit.runner.JUnitCore.run(JUnitCore.java:136)
      at org.ops4j.pax.exam.invoker.junit.internal.JUnitProbeInvoker.invokeViaJUnit(JUnitProbeInvoker.java:108)
      ... 26 more

      #]

      In addition, in order to pass T1_SamplesTest, jaxrs sample needs to be modified.

        Activity

        Hide
        TangYong added a comment -

        The discussion content of between Sahoo and me is as following:

        > [Reason]
        > > In org.glassfish.fighterfish.sample.uas.simplejaxrs.Register class,
        > > getIt() is annotated @POST, and getLogin is annotated @Get, So, the
        > > isssue happened.
        Yep
        > > [Fixing]
        > > Firstly, we should make getLogin annotated as @POST from Register
        > > class's meaning.
        > >
        > > Secondly, only changing getLogin annotated as @POST is not enough,
        > > because getIt()'s @Path is same as getLogin. So, we should do an
        > > difference between the two methods by creating sub-Path.
        > >
        > > Here, there are two ways as following:
        > >
        > > 1.
        > >
        > > @POST
        > > @Path("/getIt")
        > > @Produces("text/plain")
        > > public String getIt()

        { > > return "Hi there!"; > > }

        > >
        > > 2.
        > >
        > > @POST
        > > @Path("/getLogin")
        > > @Produces(MediaType.TEXT_HTML)
        > > @Consumes(MediaType.TEXT_PLAIN)
        > > public String getLogin(
        > > ...
        > >
        > > I select 2,
        > > 1) because getIt() should be a dummy method
        > > 2) not modifying T1_SamplesTest(keeping
        > >
        > > final String registrationRequest = "/register?name=admin&password=admin"
        > > there.
        > >
        > > Thirdly, if doing the above modification, while executing
        > >
        > > mvn clean test -Dglassfish.home=D:\20130125\glassfish4\glassfish
        > > -Dtest=SingleTest
        > >
        > > You will see the following exception(Http 415),
        > >
        > > Caused by: java.io.IOException: Server returned HTTP response code: 415
        > > for URL:
        > > http://localhost:8080/simplejaxrs/register?name=admin&password=admin
        > > ...
        I have seen this too.
        > > The reason of 415 is that Rest Consumer can not consume requested MIME
        > > type.[1]
        > > [1]: http://docs.oracle.com/cd/E19776-01/820-4867/ggqqr/
        > >
        > > So, we must add "connection.setRequestProperty("Content-Type",
        > > "text/plain"); " into getHttpResponse method of WebAppBundle class.
        > >
        > > [Discuss]
        > > Based on the above analyse, there is a drawback in "Thirdly",
        > >
        > > "connection.setRequestProperty("Content-Type", "text/plain"); " is hard
        > > coded in our test util. So, we should make user to select right
        > > "Content-Type", if he/she has not provided a "Content-Type", defaultly,
        > > we do not set the "Content-Type".
        > >
        > > However, this will change Inf of WebAppBundle class and make a large
        > > modification for T2 and T1 tests.
        > >
        > > So, I do not suggest to do it and instead, I suggest providing another
        > > method(eg. getHttpPostResponseForRest(String relativePath, String
        > > contentType)) to handle T1 scene.
        > >
        > > Of course, we should consider to use Apache httpclient library and you
        > > have also created a issue(GLASSFISH-20088).
        Add a method in WAB.getHttpPostResponse(

        String relativePath, String contentType)

        > >
        > > Finally, a litter suggestion, the following
        > >
        > > @POST
        > > @Produces(MediaType.TEXT_HTML)
        > > @Consumes(MediaType.TEXT_PLAIN)
        > > public String getLogin(
        > > @Context HttpServletRequest request,
        > > @Context HttpServletResponse response
        > > ) throws ServletException {
        > > String name = request.getParameter("name");
        > > String password = request.getParameter("password");
        > > ...
        > >
        > > whether can change into by using @QueryParam, and more easy?
        Yes.

        Sahoo
        > > @POST
        > > @Produces(MediaType.TEXT_HTML)
        > > @Consumes(MediaType.TEXT_PLAIN)
        > > public String getLogin(
        > > @QueryParam("name") String name,
        > > @QueryParam("password") String password
        > > ) throws ServletException {
        > > try {
        > > if (uas.register(name, password)) {
        > > ...
        > >

        Show
        TangYong added a comment - The discussion content of between Sahoo and me is as following: > [Reason] > > In org.glassfish.fighterfish.sample.uas.simplejaxrs.Register class, > > getIt() is annotated @POST, and getLogin is annotated @Get, So, the > > isssue happened. Yep > > [Fixing] > > Firstly, we should make getLogin annotated as @POST from Register > > class's meaning. > > > > Secondly, only changing getLogin annotated as @POST is not enough, > > because getIt()'s @Path is same as getLogin. So, we should do an > > difference between the two methods by creating sub-Path. > > > > Here, there are two ways as following: > > > > 1. > > > > @POST > > @Path("/getIt") > > @Produces("text/plain") > > public String getIt() { > > return "Hi there!"; > > } > > > > 2. > > > > @POST > > @Path("/getLogin") > > @Produces(MediaType.TEXT_HTML) > > @Consumes(MediaType.TEXT_PLAIN) > > public String getLogin( > > ... > > > > I select 2, > > 1) because getIt() should be a dummy method > > 2) not modifying T1_SamplesTest(keeping > > > > final String registrationRequest = "/register?name=admin&password=admin" > > there. > > > > Thirdly, if doing the above modification, while executing > > > > mvn clean test -Dglassfish.home=D:\20130125\glassfish4\glassfish > > -Dtest=SingleTest > > > > You will see the following exception(Http 415), > > > > Caused by: java.io.IOException: Server returned HTTP response code: 415 > > for URL: > > http://localhost:8080/simplejaxrs/register?name=admin&password=admin > > ... I have seen this too. > > The reason of 415 is that Rest Consumer can not consume requested MIME > > type. [1] > > [1] : http://docs.oracle.com/cd/E19776-01/820-4867/ggqqr/ > > > > So, we must add "connection.setRequestProperty("Content-Type", > > "text/plain"); " into getHttpResponse method of WebAppBundle class. > > > > [Discuss] > > Based on the above analyse, there is a drawback in "Thirdly", > > > > "connection.setRequestProperty("Content-Type", "text/plain"); " is hard > > coded in our test util. So, we should make user to select right > > "Content-Type", if he/she has not provided a "Content-Type", defaultly, > > we do not set the "Content-Type". > > > > However, this will change Inf of WebAppBundle class and make a large > > modification for T2 and T1 tests. > > > > So, I do not suggest to do it and instead, I suggest providing another > > method(eg. getHttpPostResponseForRest(String relativePath, String > > contentType)) to handle T1 scene. > > > > Of course, we should consider to use Apache httpclient library and you > > have also created a issue( GLASSFISH-20088 ). Add a method in WAB.getHttpPostResponse( String relativePath, String contentType) > > > > Finally, a litter suggestion, the following > > > > @POST > > @Produces(MediaType.TEXT_HTML) > > @Consumes(MediaType.TEXT_PLAIN) > > public String getLogin( > > @Context HttpServletRequest request, > > @Context HttpServletResponse response > > ) throws ServletException { > > String name = request.getParameter("name"); > > String password = request.getParameter("password"); > > ... > > > > whether can change into by using @QueryParam, and more easy? Yes. Sahoo > > @POST > > @Produces(MediaType.TEXT_HTML) > > @Consumes(MediaType.TEXT_PLAIN) > > public String getLogin( > > @QueryParam("name") String name, > > @QueryParam("password") String password > > ) throws ServletException { > > try { > > if (uas.register(name, password)) { > > ... > >
        Hide
        TangYong added a comment -

        first fixing jaxrs sample.

        Revisions:
        ----------
        61001

        Show
        TangYong added a comment - first fixing jaxrs sample. Revisions: ---------- 61001
        Hide
        TangYong added a comment -

        check in test.util to add a getHttpPostResponse(String relativePath, String contentType) method for WebAppBundle class

        Revisions:
        ----------
        61002

        Show
        TangYong added a comment - check in test.util to add a getHttpPostResponse(String relativePath, String contentType) method for WebAppBundle class Revisions: ---------- 61002
        Hide
        TangYong added a comment -

        waiting for jaxrs sample and test.util to release new version, then check in test.it.

        Show
        TangYong added a comment - waiting for jaxrs sample and test.util to release new version, then check in test.it.
        Hide
        TangYong added a comment -

        check in T1_SamplesTest and ExpectedTestResult.txt

        Revision: 61056

        Show
        TangYong added a comment - check in T1_SamplesTest and ExpectedTestResult.txt Revision: 61056

          People

          • Assignee:
            TangYong
            Reporter:
            TangYong
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: