Java org.jboss.arquillian.container.test.api.RunAsClient 代码实例

・16 分钟阅读

以下是展示如何使用org.jboss.arquillian.container.test.api.RunAsClient的最佳示例。 我们使用了代码质量辨别算法从开源项目中提取出了最佳的优秀示例。

实例 1


@Test
@RunAsClient
public void submittedConferenceShouldBeSaved(Instance<List<Conference>> conferencesInstance) throws Exception {
    Warp.execute(new ClientAction() {
        public void action() {
            browser.navigate().to(contextPath + "submit.jsf");
        }
    }).verify(new VerifyInitialState());
    browser.findElement(By.id("conference:title")).sendKeys("Devoxx");
    browser.findElement(By.id("conference:startDate")).sendKeys("2010-11-15");
    browser.findElement(By.id("conference:endDate")).sendKeys("2010-11-19");
    browser.findElement(By.id("conference:location")).sendKeys("Metropolis, Antwerp, Belgium");
    browser.findElement(By.id("conference:topic")).sendKeys("Java");
    Warp.execute(new ClientAction() {
        public void action() {
            browser.findElement(By.id("conference:submit")).click();
        }
    }).verify(new VerifySubmission());
    assertEquals("Conference Summary", browser.getTitle());
    assertEquals("Devoxx", browser.findElement(By.id("title")).getText());
}
 

实例 2


@Test
@RunAsClient
public void testAjaxGetStocks() {
    Warp.initiate(new Activity() {
        @Override
        public void perform() {
            browser.navigate().to(contextPath + "restclient.jsp");
        }
    }).group().observe(request().uri().endsWith("/stocks")).inspect(new Inspection() {
        private static final long serialVersionUID = 1L;
        @ArquillianResource
        private RestContext restContext;
        @AfterServlet
        public void testGetStocks() {
            assertThat(restContext.getHttpRequest().getMethod()).isEqualTo(HttpMethod.GET);
            assertThat(restContext.getHttpResponse().getStatusCode()).isEqualTo(Response.Status.OK.getStatusCode());
            assertThat(restContext.getHttpResponse().getContentType()).isEqualTo("application/json");
            List list = (List) restContext.getHttpResponse().getEntity();
            assertThat(list.size()).isEqualTo(1);
        }
    });
}
 

实例 3


@Test
@RunAsClient
public void testAjaxGetStock() {
    browser.navigate().to(contextPath + "restclient.jsp");
    Warp.initiate(new Activity() {
        @Override
        public void perform() {
            browser.findElement(By.className("stockLink")).click();
        }
    }).group().observe(request().uri().endsWith("/stocks/1")).inspect(new Inspection() {
        private static final long serialVersionUID = 1L;
        @ArquillianResource
        private RestContext restContext;
        @AfterServlet
        public void testGetStock() {
            assertThat(restContext.getHttpRequest().getMethod()).isEqualTo(HttpMethod.GET);
            assertThat(restContext.getHttpResponse().getStatusCode()).isEqualTo(Response.Status.OK.getStatusCode());
            assertThat(restContext.getHttpResponse().getContentType()).isEqualTo("application/json");
            Stock stock = (Stock) restContext.getHttpResponse().getEntity();
            assertThat(stock.getId()).isEqualTo(1L);
            assertThat(stock.getName()).isEqualTo("Acme");
            assertThat(stock.getCode()).isEqualTo("ACM");
        }
    });
}
 

实例 4


@Test
@RunAsClient
public void test() {
    Warp.execute(new ClientAction() {
        public void action() {
            browser.navigate().to(contextPath + "index.html");
        }
    }).verify(new InitialRequestAssertion());
    // final WebElement sendAjax = new WebDriverWait(browser, 60).until(new Function<WebDriver, WebElement>() {
    // public WebElement apply(WebDriver input) {
    // return browser.findElement(By.id("sendAjax"));
    // }
    // });
    // Warp.execute(new ClientAction() {
    // public void action() {
    // sendAjax.click();
    // }
    // }).verify(new AjaxRequestAssertion());
}
 

实例 5


@RunAsClient
@Test
public void test() {
    browser.navigate().to(portalURL);
    Warp
        .initiate(new Activity() {
            @Override
            public void perform() {
                inputField.clear();
                inputField.sendKeys(NEW_VALUE);
                submitButton.click();
            }
        })
        .group()
            .observe(request().index(1))
            .inspect(new Inspection() {
                private static final long serialVersionUID = 1L;
                @ManagedProperty("#{bean}")
                Bean bean;
                @PortletPhase(ACTION) @BeforePhase(Phase.UPDATE_MODEL_VALUES)
                public void testBeanValueBeforeUpdate() {
                    assertEquals("Bean value should not be updated yet.", Bean.HELLO_JSF_PORTLET, bean.getText());
                }
                @PortletPhase(ACTION) @AfterPhase(Phase.UPDATE_MODEL_VALUES)
                public void testBeanValueAfterUpdate() {
                    assertEquals("Bean value should now be updated.", NEW_VALUE, bean.getText());
                }
            })
        .group()
            .observe(request().index(2))
            .inspect(new Inspection() {
                private static final long serialVersionUID = 1L;
                @ManagedProperty("#{bean}")
                Bean bean;
                @PortletPhase(RENDER) @BeforePhase(Phase.RENDER_RESPONSE)
                public void testBeanValueBeforeRenderResponse() {
                    assertEquals("Bean value should still contain new value.", NEW_VALUE, bean.getText());
                }
            })
        .execute();
}
 

实例 6


@Test
@RunAsClient
public void portletAction() throws Exception {
    browser.navigate().to(portalURL);
    Warp
        .initiate(new Activity() {
            @Override
            public void perform() {
                submitButton.click();
            }
        })
        .group()
            .observe(request().index(1))
            .inspect(new Inspection() {
                private static final long serialVersionUID = 1L;
                @ArquillianResource
                ActionResponse actionResponse;
                @BeforePortletPhase(Phase.ACTION)
                public void beforeActionRequest() {
                    String[] values = actionResponse.getRenderParameterMap().get("data");
                    assertNull("Render parameter for data should not be set.", values);
                }
                @AfterPortletPhase(Phase.ACTION)
                public void afterActionRequest() {
                    String[] values = actionResponse.getRenderParameterMap().get("data");
                    assertTrue("Render parameter for data should be set.", values.length == 1);
                    assertEquals("Render parameter set to incorrect value.", BasicPortlet.ACTION, values[0]);
                }
            })
        .group()
            .observe(request().index(2))
            .inspect(new Inspection() {
                private static final long serialVersionUID = 1L;
                @ArquillianResource
                RenderRequest renderRequest;
                @BeforePortletPhase(Phase.RENDER)
                public void beforeRenderRequest() {
                    String value = renderRequest.getParameter("data");
                    assertEquals("Render parameter set to incorrect value.", BasicPortlet.ACTION, value);
                }
            })
        .execute();
}
 

实例 7


/**
 *   With EAP 5.2.0. config.
 */
@Test @Category( EAP.class )
@RunAsClient
public void testClassloadingMigrator( ) throws Exception {
    Configuration conf = TestAppConfig.createTestConfig_EAP_520("production");
    conf.getGlobal().addDeploymentPath( createDeploymentJar().getPath() );
    conf.getGlobal().addDeploymentPath( createDeploymentWar().getPath() );
    AS7Config as7Config = conf.getGlobal().getAS7Config();
    ModelControllerClient as7client = ModelControllerClient.Factory.create(as7Config.getHost(), as7Config.getManagementPort());
    // Query for the server path.
    String as7Dir = AS7CliUtils.queryServerHomeDir( as7client );
    if( as7Dir != null )  // AS 7.1.1 doesn't define it.
        conf.getGlobal().getAS7Config().setDir( as7Dir );
    TestUtils.announceMigration( conf );
    ConfigurationValidator.validate( conf );
    MigrationEngine migrator = new MigrationEngine(conf);
    migrator.doMigration();
}
 

实例 8


/**
    <a>
        <foo name="foo1" value="fooValue"/>
        <bar name="bar1">
            <value>barValue</value>
        </bar> 
    </a>
 */
@Test @RunAsClient
public void testXmlQuery() throws Exception {
    TestUtils.printTestBanner();
    MigrationEngine migEngine = 
    doTest( "XmlQueryTest", null, new TestPreparation() {
        @Override public void prepareDir( File dir ) throws Exception {
            ClassUtils.copyResourceToDir( this.getClass(), "xmlQueryTest.xml", dir );
            ClassUtils.copyResourceToDir( this.getClass(), "AttrBeanGroovy.groovy", dir );
        }
        @Override public void prepareConfig( Configuration conf ) throws Exception { }
    } );
    final List<IMigrationAction> actions = migEngine.getContext().getActions();
    Assert.assertEquals("1 action created", 1, actions.size());
    final List<String> warnings = migEngine.getContext().getActions().get(0).getWarnings();
    Assert.assertEquals("1 warning in action", 1, warnings.size());
    final String warn = warnings.get(0);
    System.out.println("The warning produced:n    " + warn );
    Assert.assertTrue("Warning contains fooValue", warn.contains("fooValue"));
    Assert.assertTrue("Warning contains barValue", warn.contains("barValue"));
}
 

实例 9


@Test
@RunAsClient
public void testNavigation() throws MalformedURLException
{
    driver.get(new URL(contextPath, "simplePageConfig.xhtml").toString());
    Assert.assertTrue(ExpectedConditions.textToBePresentInElement(By.id("pageBean002Called"), "true").apply(driver));
}
 

实例 10


@Test
@RunAsClient
public void testNavigation() throws MalformedURLException
{
    driver.get(new URL(contextPath, "simplePageConfig.xhtml").toString());
    Assert.assertTrue(ExpectedConditions.textToBePresentInElement(By.id("pageBean001Called"), "true").apply(driver));
}
 

实例 11


@Test
@RunAsClient
public void testPutGetTranslationWithExtension() throws Exception {
    final TranslationsResource resource =
            translationTestFactory.getTextFlowTargetCommentTest();
    final AtomicReference<String> processId = new AtomicReference<>(null);
    new ResourceRequest(
            getRestEndpointUrl("async/projects/p/sample-project/iterations/i/1.0/r/my,path,document.txt/translations/en"),
            "PUT", getAuthorizedEnvironment()) {
        @Override
        protected void prepareRequest(ClientRequest request) {
            request.getQueryParameters().add("ext", "gettext");
            request.getQueryParameters().add("ext", "comment");
            request.queryParameter("merge", "auto");
            request.body(MediaType.APPLICATION_XML_TYPE,
                    jaxbMarhsal(resource).getBytes());
        }
        @Override
        protected void onResponse(ClientResponse response) {
            assertThat(response.getStatus(), is(200));
            assertJaxbUnmarshal(response, ProcessStatus.class);
            ProcessStatus status =
                    jaxbUnmarshal(response, ProcessStatus.class);
            assertThat(status.getUrl(), is(notNullValue()));
            processId.set(status.getUrl());
        }
    }.run();
    waitAtMost(Duration.TEN_SECONDS)
            .catchUncaughtExceptions()
            .pollInterval(Duration.ONE_SECOND)
            .until(asyncPushFinishCallable(processId.get()));
}
 

实例 12


@Test
@RunAsClient
public void startCopyTrans() throws Exception {
    new ResourceRequest(
            getRestEndpointUrl(
                    String.format("copytrans/proj/%s/iter/%s/doc/%s",
                            "sample-project", "1.0",
                            resource.getName())),
                    "POST", getAuthorizedEnvironment()) {
        @Override
        protected void prepareRequest(ClientRequest request) {
        }
        @Override
        protected void onResponse(ClientResponse response) {
            Assertions.assertThat(response.getStatus()).isEqualTo(200);
            assertJaxbUnmarshal(response, CopyTransStatus.class);
        }
    }.run();
}
 

实例 13


@Test
@RunAsClient
public void testServerSide() throws Exception
{
   URL url = new URL("http://" + getServerHost() + ":" + getServerPort(CXF_TESTS_GROUP_QUALIFIER, JMS_SERVER) + "/jaxws-cxf-jms-api");
   assertEquals("true", IOUtils.readAndCloseStream(url.openStream()));
}
 

实例 14


@Test
@RunAsClient
public void testJMSEndpointServerSide() throws Exception
{
   URL url = new URL("http://" + getServerHost() + ":" + getServerPort(CXF_TESTS_GROUP_QUALIFIER, JMS_SERVER) + "/jaxws-cxf-jms-only-deployment-test-servlet");
   assertEquals("true", IOUtils.readAndCloseStream(url.openStream()));
}
 
讨论
淘淘あ西西 profile image