Java tutorial
/* * Copyright (C) 2017 FormKiQ Inc. * * 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.formkiq.web; import static com.formkiq.core.form.FormFinder.findValueByKey; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.DEFINED_PORT; import java.util.Date; import java.util.List; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.security.authentication.UsernamePasswordAuthenticationToken; import org.springframework.security.core.Authentication; import org.springframework.security.core.context.SecurityContextHolder; import org.springframework.security.oauth2.provider.OAuth2Authentication; import org.springframework.test.context.ActiveProfiles; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import com.formkiq.core.equifax.service.EquifaxFormEventHandler; import com.formkiq.core.equifax.service.EquifaxServiceLocal; import com.formkiq.core.form.JSONService; import com.formkiq.core.form.dto.FormJSON; import com.formkiq.core.service.FormBuiltInObjectBuilder; import com.formkiq.core.util.Resources; import com.google.common.base.Predicate; /** * WorkflowController Edit Integration Test. * */ @RunWith(SpringJUnit4ClassRunner.class) @SpringBootTest(classes = Application.class, webEnvironment = DEFINED_PORT) @ActiveProfiles("dev") public class EquifaxIntegrationTest extends SeleniumTestBase { /** {@link EquifaxFormEventHandler}. */ @Autowired private EquifaxFormEventHandler equifaxHandler; /** {@link EquifaxServiceLocal}. */ @Autowired private EquifaxServiceLocal equifaxService; /** {@link JSONService}. */ @Autowired private JSONService jsonService; /** {@link FormBuiltInObjectBuilder}. */ private FormBuiltInObjectBuilder ob = new FormBuiltInObjectBuilder(); @Override @Before public void before() throws Exception { super.before(); truncateTables("equifax_credit_checks"); String resp = Resources.getResourceAsString("/equifax/response.txt"); this.equifaxService.setResponse(resp); } /** * test empty equifax. * * @throws Exception Exception */ @Test public void testEmptyTable() throws Exception { // given // when login(getDefaultEmail()); getDriver().navigate().to(getDefaultHostAndPort() + "/admin/equifax"); // then assertEquals("FormKiQ Server - Equifax", getTitle()); waitUntil(new Predicate<WebDriver>() { @Override public boolean apply(final WebDriver d) { WebElement e = findElements(By.xpath("//table[@id='results']")).get(0); return e.getText().contains("No Equifax Credit Check(s)"); } }); } /** * test non empty equifax. * * @throws Exception Exception */ @Test public void testEquifaxData() throws Exception { // given Authentication auth = new OAuth2Authentication(null, new UsernamePasswordAuthenticationToken("test", "test")); SecurityContextHolder.getContext().setAuthentication(auth); FormJSON form = this.ob.getEquifaxcc(this.jsonService); findValueByKey(form, "firstname").get().setValue("John"); findValueByKey(form, "familyname").get().setValue("Smith"); findValueByKey(form, "birthdate").get().setValue(this.jsonService.dateToString(new Date())); this.equifaxHandler.handleEvent(form, "any"); // when login(getDefaultEmail()); getDriver().navigate().to(getDefaultHostAndPort() + "/admin/equifax"); // then assertEquals("FormKiQ Server - Equifax", getTitle()); waitUntil(new Predicate<WebDriver>() { @Override public boolean apply(final WebDriver d) { WebElement e = findElements(By.xpath("//table[@id='results']")).get(0); return e.getText().contains("THOMAS"); } }); int i = 0; final int size = 6; List<WebElement> e = findElements(By.xpath("//table[@id='results']/tbody/tr/td")); assertEquals(size, e.size()); assertNotNull(e.get(i++).getText()); assertEquals("NEW", e.get(i++).getText()); assertEquals("https://uat.equifax.ca/sts/processinquiry.asp", e.get(i++).getText()); assertEquals("test", e.get(i++).getText()); assertNotNull(e.get(i++).getText()); assertNotNull(e.get(i++).getText()); } }