On Github mmatloka / arq-extensions-presentation
Michał Matłoka / @mmatloka
Oh hey, these are some notes. They'll be hidden in your presentation, but you can see them if you open the speaker notes window (hit 's' on your keyboard).Company with traditions
@RunWith(Arquillian.class) public class SomeTest { @Deployment public static Archive<?> createDeployment() { return ... } @Inject private Something something; @Test public void should..() { ... } }
WebArchive webArchive = ShrinkWrap.create(WebArchive.class) .addClass(User.class) .addAsManifestResource(EmptyAsset.INSTANCE, "beans.xml");
WebArchive webArchive = ShrinkWrap.create(WebArchive.class) .addClasses(User.class, ...) .addAsManifestResource(EmptyAsset.INSTANCE, "beans.xml");
WebArchive webArchive = ShrinkWrap.create(WebArchive.class) .addPackage(User.class.getPackage()) .addAsManifestResource(EmptyAsset.INSTANCE, "beans.xml");
File[] files = Maven.resolver() .resolve("G:A:V") .withTransitivity() .asFile();
File[] files = Maven.resolver() .loadPomFromFile("/path/to/pom.xml") .resolve("G:A") .withTransitivity() .asFile();
File[] files = Maven.resolver() .loadPomFromFile("/path/to/pom.xml") .importRuntimeDependencies() .resolve().withTransitivity() .asFile();
WebArchive webArchive = ShrinkWrap.create(MavenImporter.class) .loadPomFromFile("/path/to/pom.xml") .importBuildOutput() .as(WebArchive.class);
WebArchive webArchive = ShrinkWrap .create(EmbeddedGradleImporter.class) .forProjectDirectory(dir) .importBuildOutput() .as(WebArchive.class);
<persistence> <persistence-unit name="myapp"> <provider>org.hibernate.ejb.HibernatePersistence</provider> <jta-data-source>java:/DefaultDS</jta-data-source> <properties> <property name="hibernate.dialect" value="org.hibernate.dialect.HSQLDialect"> <property name="hibernate.hbm2ddl.auto" value="create-drop"> </property></property></properties> </persistence-unit> </persistence>
final PersistenceDescriptor persistence = Descriptors .create(PersistenceDescriptor.class) .createPersistenceUnit() .name("myapp") .provider("org.hibernate.ejb.HibernatePersistence") .jtaDataSource("java:/DefaultDS") .getOrCreateProperties() .createProperty().name("hibernate.dialect") .value("org.hibernate.dialect.HSQLDialect").up() .createProperty().name("hibernate.hbm2ddl.auto") .value("create-drop").up() .up().up()
@Test @UsingDataSet("datasets/users.yml") @ShouldMatchDataSet("datasets/expected-users.yml") public void shouldChangeUserPassword() throws Exception { // given final String expectedPassword = "lubiePlacki"; final User user = em.find(User.class, 2L); // when user.setPassword(expectedPassword); em.merge(user); // then assertThat(user.getPassword()).isEqualTo(expectedPassword); }
user: - id: 1 firstname: John lastname: Smith username: doovde password: password - id: 2 firstname: Clark lastname: Kent username: superman password: kryptonite
@RunWith(Arquillian.class) public class WebDriverTest { @Deployment(testable = false) public static WebArchive createDeployment() ... @ArquillianResource URL contextPath; @Drone WebDriver driver; @Test public void shouldNotLogin() { driver.findElement(By.id("loginForm:login")).click(); ... }}
@RunWith(Arquillian.class) public class TestLogin { @Drone WebDriver browser; @Page HomePage homePage; @Test(expects = LoginFailedException.class) public void testLoginFailed() {} homePage.login("non-existent", "user"); }}
public class HomePage { @FindBy(".login-form") LoginDialog loginDialog; @FindBy(".search") AutocompleteComponent fulltextSearch; public void login(String user, String password) throws LoginFailedException { loginDialog.setUser(user); loginDialog.setPassword(password); loginDialog.login(); } ... }
public class LoginDialog { @FindBy private WebElement userName; @FindBy(id = "login") private WebElement loginButton; .... }
Graphene.waitAjax().until().element(webElementOrBy).is(). .is().not().present(); .enabled(); .selected(); .visible();
@RunWith(Arquillian.class) @WarpTest @RunAsClient public class BasicTest { @Deployment ... @ArquillianResource URL contextPath; @Test public void should...() { Warp .initiate(Activity) .observe(Observer) .inspect(Inspection); }}
@Test public void shouldMakeProperRequest() { Warp.initiate(new Activity() { @Override public void perform() { browser.navigate().to(contextPath + "/cart"); } }).group().observe(request().uri().endsWith("/cart")) .inspect(inspection); }
Inspection inspection = 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); } }
@RunWith(Arquillian.class) @RunAsClient public class DroidiumWebTestCase { @Deployment @TargetsContainer("jbossas") public static Archive<?> getDeployment() { return ShrinkWrap .createFromZipFile(WebArchive.class, new File("shop.war")); } @Test @OperateOnDeployment("jbossas") public void test01(@Drone AndroidDriver driver, @ArquillianResource URL deploymentURL) {L driver.get(deploymentURL.toString()); assertTrue(driver.getPageSource().contains("Shop")); }}
@RunWith(Arquillian.class) @RunAsClient public class DroidiumSelendroidTestCase { @Deployment @Instrumentable public static Archive<?> getDeployment() { return ShrinkWrap .createFromZipFile(JavaArchive.class, new File("shop.apk")); } @Test public void example(@ArquillianResource AndroidDevice android, @Drone WebDriver driver) { android.getActivityManagerProvider().getActivityManager() .startActivity("com.shop.HomeScreenActivity") WebElement button = driver .findElement(By.id("cartButton")); ... }}
@PerformanceTest(resultsThreshold=2) // checks if resultsThreshold * newTime < oldTime @RunWith(Arquillian.class) public class RecommendationBuildingTest { @Deployment public static JavaArchive createDeployment() { return ... } @Inject RecommendationService recommendationService; @Test @Performance(time=20) // timeout in ms public void doHardWork() throws Exception { ... } }
http://meninblack.wikia.com/