Bael 4461 2 (#4444)
* [BAEL-4462] - Fixed integration tests * [BAEL-4462] - Fixed integration tests * [BAEL-4462] - Fixed integration tests * [BAEL-4462] - Fixed integration tests * [BAEL-4462] - Fixed integration tests * [BAEL-4462] - Fixed integration tests * [BAEL-4462] - Fixed integration tests * [BAEL-4462] - Fixed integration tests * [BAEL-4462] - Fixed integration tests * [BAEL-4462] - Fixed integration tests * [BAEL-4462] - Fixed integration tests * [BAEL-4462] - Fixed integration tests * [BAEL-4462] - Fixed integration tests * [BAEL-4462] - Fixed integration tests * Fix verification times
This commit is contained in:
parent
096826cc07
commit
a54c9e0c9e
|
@ -1,25 +1,30 @@
|
|||
package com.baeldung.poi.powerpoint;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.poi.xslf.usermodel.XMLSlideShow;
|
||||
import org.apache.poi.xslf.usermodel.XSLFShape;
|
||||
import org.apache.poi.xslf.usermodel.XSLFSlide;
|
||||
import org.junit.After;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.List;
|
||||
import org.junit.rules.TemporaryFolder;
|
||||
|
||||
public class PowerPointIntegrationTest {
|
||||
|
||||
private PowerPointHelper pph;
|
||||
private String fileLocation;
|
||||
private static final String FILE_NAME = "presentation.pptx";
|
||||
|
||||
@Rule
|
||||
public TemporaryFolder tempFolder = new TemporaryFolder();
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
File currDir = new File(".");
|
||||
File currDir = tempFolder.newFolder();
|
||||
String path = currDir.getAbsolutePath();
|
||||
fileLocation = path.substring(0, path.length() - 1) + FILE_NAME;
|
||||
|
||||
|
|
|
@ -46,7 +46,7 @@ public class JaggedArrayUnitTest {
|
|||
ByteArrayOutputStream outContent = new ByteArrayOutputStream();
|
||||
System.setOut(new PrintStream(outContent));
|
||||
obj.printElements(jaggedArr);
|
||||
assertEquals("[1, 2]\n[3, 4, 5]\n[6, 7, 8, 9]\n", outContent.toString());
|
||||
assertEquals("[1, 2][3, 4, 5][6, 7, 8, 9]", outContent.toString().replace("\r", "").replace("\n", ""));
|
||||
System.setOut(System.out);
|
||||
}
|
||||
|
||||
|
|
|
@ -179,7 +179,7 @@ public class JavaMoneyUnitManualTest {
|
|||
MonetaryAmountFormat customFormat = MonetaryFormats.getAmountFormat(AmountFormatQueryBuilder
|
||||
.of(Locale.US)
|
||||
.set(CurrencyStyle.NAME)
|
||||
.set("pattern", "00000.00 <EFBFBD>")
|
||||
.set("pattern", "00000.00 US Dollar")
|
||||
.build());
|
||||
String customFormatted = customFormat.format(oneDollar);
|
||||
|
||||
|
|
|
@ -104,7 +104,7 @@ public class NashornUnitTest {
|
|||
public void loadExamples() throws ScriptException {
|
||||
Object loadResult = engine.eval("load('classpath:js/script.js');" + "increment(5)");
|
||||
|
||||
Assert.assertEquals(6.0, loadResult);
|
||||
Assert.assertEquals(6, ((Double) loadResult).intValue());
|
||||
|
||||
Object math = engine.eval("var math = loadWithNewGlobal('classpath:js/math_module.js');" + "math.increment(5);");
|
||||
|
||||
|
|
|
@ -5,6 +5,7 @@ import java.util.concurrent.ConcurrentHashMap;
|
|||
|
||||
import javax.annotation.PostConstruct;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import com.couchbase.client.java.Bucket;
|
||||
|
@ -18,6 +19,11 @@ public class ClusterServiceImpl implements ClusterService {
|
|||
|
||||
private Cluster cluster;
|
||||
private Map<String, Bucket> buckets = new ConcurrentHashMap<>();
|
||||
|
||||
@Autowired
|
||||
public ClusterServiceImpl(Cluster cluster) {
|
||||
this.cluster = cluster;
|
||||
}
|
||||
|
||||
@PostConstruct
|
||||
private void init() {
|
||||
|
|
|
@ -18,6 +18,7 @@ public class TutorialBucketService extends AbstractBucketService {
|
|||
@Autowired
|
||||
public TutorialBucketService(ClusterService clusterService) {
|
||||
super(clusterService);
|
||||
openBucket();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -0,0 +1,24 @@
|
|||
package com.baeldung.couchbase.async.person;
|
||||
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.ComponentScan;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
import com.couchbase.client.java.Cluster;
|
||||
import com.couchbase.client.java.CouchbaseCluster;
|
||||
import com.couchbase.client.java.env.CouchbaseEnvironment;
|
||||
import com.couchbase.client.java.env.DefaultCouchbaseEnvironment;
|
||||
|
||||
@Configuration
|
||||
@ComponentScan(basePackages = {"com.baeldung.couchbase.async.service", "com.baeldung.couchbase.n1ql"})
|
||||
public class PersonCrudServiceIntegrationTestConfig {
|
||||
|
||||
@Bean
|
||||
public Cluster cluster() {
|
||||
CouchbaseEnvironment env = DefaultCouchbaseEnvironment.builder()
|
||||
.connectTimeout(60000)
|
||||
.build();
|
||||
return CouchbaseCluster.create(env, "127.0.0.1");
|
||||
}
|
||||
|
||||
}
|
|
@ -1,27 +1,31 @@
|
|||
package com.baeldung.couchbase.async.person;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
|
||||
import org.apache.commons.lang3.RandomStringUtils;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Qualifier;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
import com.baeldung.couchbase.async.AsyncIntegrationTest;
|
||||
import com.baeldung.couchbase.async.person.Person;
|
||||
import com.baeldung.couchbase.async.person.PersonCrudService;
|
||||
import com.baeldung.couchbase.async.person.PersonDocumentConverter;
|
||||
import com.baeldung.couchbase.async.service.BucketService;
|
||||
import com.couchbase.client.java.Bucket;
|
||||
import com.couchbase.client.java.document.JsonDocument;
|
||||
|
||||
public class PersonCrudServiceIntegrationTest extends AsyncIntegrationTest {
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@ContextConfiguration(classes = {PersonCrudServiceIntegrationTestConfig.class})
|
||||
public class PersonCrudServiceLiveTest extends AsyncIntegrationTest {
|
||||
|
||||
@Autowired
|
||||
private PersonCrudService personService;
|
||||
|
@ -35,8 +39,8 @@ public class PersonCrudServiceIntegrationTest extends AsyncIntegrationTest {
|
|||
|
||||
private Bucket bucket;
|
||||
|
||||
@PostConstruct
|
||||
private void init() {
|
||||
@Before
|
||||
public void init() {
|
||||
bucket = bucketService.getBucket();
|
||||
}
|
||||
|
|
@ -18,7 +18,7 @@ import com.couchbase.client.java.Bucket;
|
|||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@ContextConfiguration(classes = { AsyncIntegrationTestConfig.class })
|
||||
@TestExecutionListeners(listeners = { DependencyInjectionTestExecutionListener.class })
|
||||
public class ClusterServiceIntegrationTest extends AsyncIntegrationTest {
|
||||
public class ClusterServiceLiveTest extends AsyncIntegrationTest {
|
||||
|
||||
@Autowired
|
||||
private ClusterService couchbaseService;
|
|
@ -14,8 +14,8 @@ import com.couchbase.client.java.document.JsonDocument;
|
|||
import com.couchbase.client.java.view.ViewResult;
|
||||
import com.couchbase.client.java.view.ViewRow;
|
||||
|
||||
public class StudentGradeServiceIntegrationTest {
|
||||
private static final Logger logger = LoggerFactory.getLogger(StudentGradeServiceIntegrationTest.class);
|
||||
public class StudentGradeServiceLiveTest {
|
||||
private static final Logger logger = LoggerFactory.getLogger(StudentGradeServiceLiveTest.class);
|
||||
|
||||
static StudentGradeService studentGradeService;
|
||||
static Set<String> gradeIds = new HashSet<>();
|
|
@ -1,5 +1,23 @@
|
|||
package com.baeldung.couchbase.n1ql;
|
||||
|
||||
import static com.baeldung.couchbase.n1ql.CodeSnippets.extractJsonResult;
|
||||
import static com.couchbase.client.java.query.Select.select;
|
||||
import static com.couchbase.client.java.query.dsl.Expression.i;
|
||||
import static com.couchbase.client.java.query.dsl.Expression.s;
|
||||
import static com.couchbase.client.java.query.dsl.Expression.x;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.IntStream;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
import com.couchbase.client.java.Bucket;
|
||||
import com.couchbase.client.java.Cluster;
|
||||
import com.couchbase.client.java.document.JsonDocument;
|
||||
|
@ -10,28 +28,13 @@ import com.couchbase.client.java.query.N1qlQueryResult;
|
|||
import com.couchbase.client.java.query.N1qlQueryRow;
|
||||
import com.couchbase.client.java.query.Statement;
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
import rx.Observable;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.IntStream;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import static com.baeldung.couchbase.n1ql.CodeSnippets.extractJsonResult;
|
||||
import static com.couchbase.client.java.query.Select.select;
|
||||
import static com.couchbase.client.java.query.dsl.Expression.*;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
|
||||
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@ContextConfiguration(classes = { IntegrationTestConfig.class })
|
||||
public class N1QLIntegrationTest {
|
||||
public class N1QLLiveTest {
|
||||
|
||||
|
||||
@Autowired
|
|
@ -10,7 +10,7 @@ import org.springframework.beans.factory.annotation.Autowired;
|
|||
|
||||
import com.baeldung.couchbase.spring.IntegrationTest;
|
||||
|
||||
public class PersonCrudServiceIntegrationTest extends IntegrationTest {
|
||||
public class PersonCrudServiceLiveTest extends IntegrationTest {
|
||||
|
||||
private static final String CLARK_KENT = "Clark Kent";
|
||||
private static final String SMALLVILLE = "Smallville";
|
|
@ -17,7 +17,7 @@ import com.couchbase.client.java.Bucket;
|
|||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@ContextConfiguration(classes = { IntegrationTestConfig.class })
|
||||
@TestExecutionListeners(listeners = { DependencyInjectionTestExecutionListener.class })
|
||||
public class ClusterServiceIntegrationTest extends IntegrationTest {
|
||||
public class ClusterServiceLiveTest extends IntegrationTest {
|
||||
|
||||
@Autowired
|
||||
private ClusterService couchbaseService;
|
|
@ -39,6 +39,11 @@
|
|||
<artifactId>commons-lang3</artifactId>
|
||||
<version>${commons-lang3.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>javax.activation</groupId>
|
||||
<artifactId>activation</artifactId>
|
||||
<version>1.1</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
|
|
|
@ -0,0 +1,9 @@
|
|||
|
||||
# Root logger
|
||||
log4j.rootLogger=INFO, file, stdout
|
||||
|
||||
# Write to console
|
||||
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
|
||||
log4j.appender.stdout.Target=System.out
|
||||
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
|
||||
log4j.appender.stdout.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n
|
|
@ -44,7 +44,7 @@ public class JaxbIntegrationTest {
|
|||
File bookFile = new File(this.getClass().getResource("/book.xml").getFile());
|
||||
String sampleBookXML = FileUtils.readFileToString(sampleBookFile, "UTF-8");
|
||||
String marshallerBookXML = FileUtils.readFileToString(bookFile, "UTF-8");
|
||||
Assert.assertEquals(sampleBookXML, marshallerBookXML);
|
||||
Assert.assertEquals(sampleBookXML.replace("\r", "").replace("\n", ""), marshallerBookXML.replace("\r", "").replace("\n", ""));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
|
@ -0,0 +1,5 @@
|
|||
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
||||
<book id="1">
|
||||
<title>Book1</title>
|
||||
<date>2016-12-16T17:28:49.718Z</date>
|
||||
</book>
|
|
@ -22,7 +22,7 @@ import org.openqa.selenium.WebElement;
|
|||
import org.openqa.selenium.support.FindBy;
|
||||
|
||||
@RunWith(Arquillian.class)
|
||||
public class ConvListValIntegrationTest {
|
||||
public class ConvListValLiveTest {
|
||||
|
||||
@ArquillianResource
|
||||
private URL deploymentUrl;
|
|
@ -21,7 +21,7 @@ import static org.hamcrest.Matchers.equalTo;
|
|||
|
||||
|
||||
@RunWith(Arquillian.class)
|
||||
public class AutomaticTimerBeanIntegrationTest {
|
||||
public class AutomaticTimerBeanLiveTest {
|
||||
|
||||
//the @AutomaticTimerBean has a method called every 10 seconds
|
||||
//testing the difference ==> 100000
|
|
@ -21,7 +21,7 @@ import static org.hamcrest.Matchers.is;
|
|||
|
||||
|
||||
@RunWith(Arquillian.class)
|
||||
public class ProgrammaticAtFixedRateTimerBeanIntegrationTest {
|
||||
public class ProgrammaticAtFixedRateTimerBeanLiveTest {
|
||||
|
||||
final static long TIMEOUT = 1000;
|
||||
final static long TOLERANCE = 500l;
|
|
@ -19,7 +19,7 @@ import static org.hamcrest.Matchers.is;
|
|||
|
||||
|
||||
@RunWith(Arquillian.class)
|
||||
public class ProgrammaticTimerBeanIntegrationTest {
|
||||
public class ProgrammaticTimerBeanLiveTest {
|
||||
|
||||
final static long TIMEOUT = 5000l;
|
||||
final static long TOLERANCE = 1000l;
|
|
@ -21,7 +21,7 @@ import static org.hamcrest.Matchers.is;
|
|||
|
||||
|
||||
@RunWith(Arquillian.class)
|
||||
public class ProgrammaticWithFixedDelayTimerBeanIntegrationTest {
|
||||
public class ProgrammaticWithFixedDelayTimerBeanLiveTest {
|
||||
|
||||
final static long TIMEOUT = 15000l;
|
||||
final static long TOLERANCE = 1000l;
|
|
@ -20,7 +20,7 @@ import static org.hamcrest.MatcherAssert.assertThat;
|
|||
import static org.hamcrest.Matchers.equalTo;
|
||||
|
||||
@RunWith(Arquillian.class)
|
||||
public class ScheduleTimerBeanIntegrationTest {
|
||||
public class ScheduleTimerBeanLiveTest {
|
||||
|
||||
private final static long TIMEOUT = 5000l;
|
||||
private final static long TOLERANCE = 1000l;
|
|
@ -15,7 +15,7 @@ import org.junit.Test;
|
|||
|
||||
import com.baeldung.jpa.model.Car;
|
||||
|
||||
public class StoredProcedureIntegrationTest {
|
||||
public class StoredProcedureLiveTest {
|
||||
|
||||
private static EntityManagerFactory factory = null;
|
||||
private static EntityManager entityManager = null;
|
|
@ -15,12 +15,13 @@ import static org.junit.Assert.assertEquals;
|
|||
public class EntryProcessorIntegrationTest {
|
||||
|
||||
private static final String CACHE_NAME = "MyCache";
|
||||
private static final String CACHE_PROVIDER_NAME = "com.hazelcast.cache.HazelcastCachingProvider";
|
||||
|
||||
private Cache<String, String> cache;
|
||||
|
||||
@Before
|
||||
public void instantiateCache() {
|
||||
CachingProvider cachingProvider = Caching.getCachingProvider();
|
||||
CachingProvider cachingProvider = Caching.getCachingProvider(CACHE_PROVIDER_NAME);
|
||||
CacheManager cacheManager = cachingProvider.getCacheManager();
|
||||
MutableConfiguration<String, String> config = new MutableConfiguration<>();
|
||||
this.cache = cacheManager.createCache(CACHE_NAME, config);
|
||||
|
@ -29,7 +30,7 @@ public class EntryProcessorIntegrationTest {
|
|||
|
||||
@After
|
||||
public void tearDown() {
|
||||
Caching.getCachingProvider().getCacheManager().destroyCache(CACHE_NAME);
|
||||
Caching.getCachingProvider(CACHE_PROVIDER_NAME).getCacheManager().destroyCache(CACHE_NAME);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
|
@ -17,6 +17,7 @@ import static org.junit.Assert.assertEquals;
|
|||
public class EventListenerIntegrationTest {
|
||||
|
||||
private static final String CACHE_NAME = "MyCache";
|
||||
private static final String CACHE_PROVIDER_NAME = "com.hazelcast.cache.HazelcastCachingProvider";
|
||||
|
||||
private Cache<String, String> cache;
|
||||
private SimpleCacheEntryListener listener;
|
||||
|
@ -24,7 +25,7 @@ public class EventListenerIntegrationTest {
|
|||
|
||||
@Before
|
||||
public void setup() {
|
||||
CachingProvider cachingProvider = Caching.getCachingProvider();
|
||||
CachingProvider cachingProvider = Caching.getCachingProvider(CACHE_PROVIDER_NAME);
|
||||
CacheManager cacheManager = cachingProvider.getCacheManager();
|
||||
MutableConfiguration<String, String> config = new MutableConfiguration<String, String>();
|
||||
this.cache = cacheManager.createCache("MyCache", config);
|
||||
|
@ -33,7 +34,7 @@ public class EventListenerIntegrationTest {
|
|||
|
||||
@After
|
||||
public void tearDown() {
|
||||
Caching.getCachingProvider().getCacheManager().destroyCache(CACHE_NAME);
|
||||
Caching.getCachingProvider(CACHE_PROVIDER_NAME).getCacheManager().destroyCache(CACHE_NAME);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
|
@ -14,7 +14,7 @@ public class JCacheIntegrationTest {
|
|||
|
||||
@Test
|
||||
public void instantiateCache() {
|
||||
CachingProvider cachingProvider = Caching.getCachingProvider();
|
||||
CachingProvider cachingProvider = Caching.getCachingProvider("com.hazelcast.cache.HazelcastCachingProvider");
|
||||
CacheManager cacheManager = cachingProvider.getCacheManager();
|
||||
MutableConfiguration<String, String> config = new MutableConfiguration<>();
|
||||
Cache<String, String> cache = cacheManager.createCache("simpleCache", config);
|
||||
|
|
|
@ -2,6 +2,6 @@
|
|||
<ConnectionManager className="com.gs.fw.common.mithra.test.ConnectionManagerForTests">
|
||||
<Property name="resourceName" value="testDb"/>
|
||||
<MithraObjectConfiguration className="com.baeldung.reladomo.Department" cacheType="partial"/>
|
||||
<MithraObjectConfiguration className="com.baeldung.reladomo.Employee " cacheType="partial"/>
|
||||
<MithraObjectConfiguration className="com.baeldung.reladomo.Employee" cacheType="partial"/>
|
||||
</ConnectionManager>
|
||||
</MithraRuntime>
|
|
@ -12,6 +12,7 @@ import org.apache.logging.log4j.Logger;
|
|||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
|
||||
public class JSONLayoutIntegrationTest extends Log4j2BaseIntegrationTest {
|
||||
|
|
|
@ -0,0 +1,9 @@
|
|||
|
||||
# Root logger
|
||||
log4j.rootLogger=INFO, file, stdout
|
||||
|
||||
# Write to console
|
||||
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
|
||||
log4j.appender.stdout.Target=System.out
|
||||
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
|
||||
log4j.appender.stdout.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n
|
|
@ -27,7 +27,9 @@ public class RedissonConfigurationIntegrationTest {
|
|||
@AfterClass
|
||||
public static void destroy() {
|
||||
redisServer.stop();
|
||||
client.shutdown();
|
||||
if (client != null) {
|
||||
client.shutdown();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
|
@ -37,7 +37,9 @@ public class RedissonIntegrationTest {
|
|||
@AfterClass
|
||||
public static void destroy() {
|
||||
redisServer.stop();
|
||||
client.shutdown();
|
||||
if (client != null) {
|
||||
client.shutdown();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
|
@ -18,26 +18,27 @@ public class AutomapInterfaceIntegrationTest {
|
|||
private ConnectionProvider connectionProvider = Connector.connectionProvider;
|
||||
private Database db = Database.from(connectionProvider);
|
||||
|
||||
private Observable<Integer> create = null;
|
||||
private Observable<Integer> truncate = null;
|
||||
private Observable<Integer> insert1, insert2 = null;
|
||||
|
||||
@Before
|
||||
public void setup() {
|
||||
create = db.update("CREATE TABLE IF NOT EXISTS EMPLOYEE(id int primary key, name varchar(255))")
|
||||
Observable<Integer> create = db.update("CREATE TABLE IF NOT EXISTS EMPLOYEE(id int primary key, name varchar(255))")
|
||||
.count();
|
||||
truncate = db.update("TRUNCATE TABLE EMPLOYEE")
|
||||
.dependsOn(create)
|
||||
.count();
|
||||
insert1 = db.update("INSERT INTO EMPLOYEE(id, name) VALUES(1, 'Alan')")
|
||||
.dependsOn(create)
|
||||
.dependsOn(truncate)
|
||||
.count();
|
||||
insert2 = db.update("INSERT INTO EMPLOYEE(id, name) VALUES(2, 'Sarah')")
|
||||
.dependsOn(create)
|
||||
.dependsOn(insert1)
|
||||
.count();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenSelectFromTableAndAutomap_thenCorrect() {
|
||||
List<Employee> employees = db.select("select id, name from EMPLOYEE")
|
||||
.dependsOn(create)
|
||||
.dependsOn(insert1)
|
||||
.dependsOn(insert2)
|
||||
.autoMap(Employee.class)
|
||||
.toList()
|
||||
|
@ -57,7 +58,7 @@ public class AutomapInterfaceIntegrationTest {
|
|||
@After
|
||||
public void close() {
|
||||
db.update("DROP TABLE EMPLOYEE")
|
||||
.dependsOn(create);
|
||||
.dependsOn(truncate);
|
||||
connectionProvider.close();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -22,24 +22,24 @@ public class BasicQueryTypesIntegrationTest {
|
|||
|
||||
@Test
|
||||
public void whenCreateTableAndInsertRecords_thenCorrect() {
|
||||
create = db.update("CREATE TABLE IF NOT EXISTS EMPLOYEE(id int primary key, name varchar(255))")
|
||||
create = db.update("CREATE TABLE IF NOT EXISTS EMPLOYEE_TABLE(id int primary key, name varchar(255))")
|
||||
.count();
|
||||
Observable<Integer> insert1 = db.update("INSERT INTO EMPLOYEE(id, name) VALUES(1, 'John')")
|
||||
Observable<Integer> insert1 = db.update("INSERT INTO EMPLOYEE_TABLE(id, name) VALUES(1, 'John')")
|
||||
.dependsOn(create)
|
||||
.count();
|
||||
Observable<Integer> update = db.update("UPDATE EMPLOYEE SET name = 'Alan' WHERE id = 1")
|
||||
Observable<Integer> update = db.update("UPDATE EMPLOYEE_TABLE SET name = 'Alan' WHERE id = 1")
|
||||
.dependsOn(create)
|
||||
.count();
|
||||
Observable<Integer> insert2 = db.update("INSERT INTO EMPLOYEE(id, name) VALUES(2, 'Sarah')")
|
||||
Observable<Integer> insert2 = db.update("INSERT INTO EMPLOYEE_TABLE(id, name) VALUES(2, 'Sarah')")
|
||||
.dependsOn(create)
|
||||
.count();
|
||||
Observable<Integer> insert3 = db.update("INSERT INTO EMPLOYEE(id, name) VALUES(3, 'Mike')")
|
||||
Observable<Integer> insert3 = db.update("INSERT INTO EMPLOYEE_TABLE(id, name) VALUES(3, 'Mike')")
|
||||
.dependsOn(create)
|
||||
.count();
|
||||
Observable<Integer> delete = db.update("DELETE FROM EMPLOYEE WHERE id = 2")
|
||||
Observable<Integer> delete = db.update("DELETE FROM EMPLOYEE_TABLE WHERE id = 2")
|
||||
.dependsOn(create)
|
||||
.count();
|
||||
List<String> names = db.select("select name from EMPLOYEE where id < ?")
|
||||
List<String> names = db.select("select name from EMPLOYEE_TABLE where id < ?")
|
||||
.parameter(3)
|
||||
.dependsOn(create)
|
||||
.dependsOn(insert1)
|
||||
|
@ -57,7 +57,7 @@ public class BasicQueryTypesIntegrationTest {
|
|||
|
||||
@After
|
||||
public void close() {
|
||||
db.update("DROP TABLE EMPLOYEE")
|
||||
db.update("DROP TABLE EMPLOYEE_TABLE")
|
||||
.dependsOn(create);
|
||||
connectionProvider.close();
|
||||
}
|
||||
|
|
|
@ -27,7 +27,7 @@ public class InsertClobIntegrationTest {
|
|||
|
||||
@Before
|
||||
public void setup() throws IOException {
|
||||
create = db.update("CREATE TABLE IF NOT EXISTS SERVERLOG (id int primary key, document CLOB)")
|
||||
create = db.update("CREATE TABLE IF NOT EXISTS SERVERLOG_TABLE (id int primary key, document CLOB)")
|
||||
.count();
|
||||
|
||||
InputStream actualInputStream = new FileInputStream("src/test/resources/actual_clob");
|
||||
|
@ -35,7 +35,7 @@ public class InsertClobIntegrationTest {
|
|||
|
||||
InputStream expectedInputStream = new FileInputStream("src/test/resources/expected_clob");
|
||||
this.expectedDocument = Utils.getStringFromInputStream(expectedInputStream);
|
||||
this.insert = db.update("insert into SERVERLOG(id,document) values(?,?)")
|
||||
this.insert = db.update("insert into SERVERLOG_TABLE(id,document) values(?,?)")
|
||||
.parameter(1)
|
||||
.parameter(Database.toSentinelIfNull(actualDocument))
|
||||
.dependsOn(create)
|
||||
|
@ -44,7 +44,7 @@ public class InsertClobIntegrationTest {
|
|||
|
||||
@Test
|
||||
public void whenSelectCLOB_thenCorrect() throws IOException {
|
||||
db.select("select document from SERVERLOG where id = 1")
|
||||
db.select("select document from SERVERLOG_TABLE where id = 1")
|
||||
.dependsOn(create)
|
||||
.dependsOn(insert)
|
||||
.getAs(String.class)
|
||||
|
@ -56,7 +56,7 @@ public class InsertClobIntegrationTest {
|
|||
|
||||
@After
|
||||
public void close() {
|
||||
db.update("DROP TABLE SERVERLOG")
|
||||
db.update("DROP TABLE SERVERLOG_TABLE")
|
||||
.dependsOn(create);
|
||||
connectionProvider.close();
|
||||
}
|
||||
|
|
|
@ -22,14 +22,14 @@ public class ReturnKeysIntegrationTest {
|
|||
@Before
|
||||
public void setup() {
|
||||
begin = db.beginTransaction();
|
||||
createStatement = db.update("CREATE TABLE IF NOT EXISTS EMPLOYEE(id int auto_increment primary key, name varchar(255))")
|
||||
createStatement = db.update("CREATE TABLE IF NOT EXISTS EMPLOYEE_SAMPLE(id int auto_increment primary key, name varchar(255))")
|
||||
.dependsOn(begin)
|
||||
.count();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenInsertAndReturnGeneratedKey_thenCorrect() {
|
||||
Integer key = db.update("INSERT INTO EMPLOYEE(name) VALUES('John')")
|
||||
Integer key = db.update("INSERT INTO EMPLOYEE_SAMPLE(name) VALUES('John')")
|
||||
.dependsOn(createStatement)
|
||||
.returnGeneratedKeys()
|
||||
.getAs(Integer.class)
|
||||
|
@ -41,7 +41,7 @@ public class ReturnKeysIntegrationTest {
|
|||
|
||||
@After
|
||||
public void close() {
|
||||
db.update("DROP TABLE EMPLOYEE")
|
||||
db.update("DROP TABLE EMPLOYEE_SAMPLE")
|
||||
.dependsOn(createStatement);
|
||||
connectionProvider.close();
|
||||
}
|
||||
|
|
|
@ -24,8 +24,11 @@ public class TransactionIntegrationTest {
|
|||
.update("CREATE TABLE IF NOT EXISTS EMPLOYEE(id int primary key, name varchar(255))")
|
||||
.dependsOn(begin)
|
||||
.count();
|
||||
Observable<Integer> truncateStatement = db.update("TRUNCATE TABLE EMPLOYEE")
|
||||
.dependsOn(createStatement)
|
||||
.count();
|
||||
Observable<Integer> insertStatement = db.update("INSERT INTO EMPLOYEE(id, name) VALUES(1, 'John')")
|
||||
.dependsOn(createStatement)
|
||||
.dependsOn(truncateStatement)
|
||||
.count();
|
||||
Observable<Integer> updateStatement = db.update("UPDATE EMPLOYEE SET name = 'Tom' WHERE id = 1")
|
||||
.dependsOn(insertStatement)
|
||||
|
|
|
@ -7,6 +7,8 @@ import org.powermock.core.classloader.annotations.PrepareForTest;
|
|||
import org.powermock.modules.junit4.PowerMockRunner;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.mockito.Mockito.times;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.powermock.api.mockito.PowerMockito.*;
|
||||
|
||||
@RunWith(PowerMockRunner.class)
|
||||
|
@ -23,7 +25,7 @@ public class PowerMockitoIntegrationTest {
|
|||
|
||||
when(collaborator.helloMethod()).thenReturn("Hello Baeldung!");
|
||||
String welcome = collaborator.helloMethod();
|
||||
Mockito.verify(collaborator).helloMethod();
|
||||
verify(collaborator).helloMethod();
|
||||
assertEquals("Hello Baeldung!", welcome);
|
||||
}
|
||||
|
||||
|
@ -42,7 +44,7 @@ public class PowerMockitoIntegrationTest {
|
|||
assertEquals("Hello Baeldung!", firstWelcome);
|
||||
assertEquals("Hello Baeldung!", secondWelcome);
|
||||
|
||||
verifyStatic(Mockito.times(2));
|
||||
verifyStatic(times(2));
|
||||
CollaboratorWithStaticMethods.firstMethod(Mockito.anyString());
|
||||
|
||||
verifyStatic(Mockito.never());
|
||||
|
@ -67,7 +69,7 @@ public class PowerMockitoIntegrationTest {
|
|||
|
||||
when(mock.finalMethod()).thenReturn("I am a final mock method.");
|
||||
returnValue = mock.finalMethod();
|
||||
Mockito.verify(mock).finalMethod();
|
||||
verify(mock,times(3)).finalMethod();
|
||||
assertEquals("I am a final mock method.", returnValue);
|
||||
|
||||
when(mock, "privateMethod").thenReturn("I am a private mock method.");
|
||||
|
|
|
@ -24,7 +24,7 @@ public class MockitoMockIntegrationTest {
|
|||
}
|
||||
|
||||
@Rule
|
||||
private ExpectedException thrown = ExpectedException.none();
|
||||
public ExpectedException thrown = ExpectedException.none();
|
||||
|
||||
@Test
|
||||
public void whenUsingSimpleMock_thenCorrect() {
|
||||
|
|
|
@ -1,19 +1,5 @@
|
|||
package com.baeldung.rest.wiremock.introduction;
|
||||
|
||||
import com.github.tomakehurst.wiremock.junit.WireMockRule;
|
||||
import org.apache.http.HttpResponse;
|
||||
import org.apache.http.client.methods.HttpGet;
|
||||
import org.apache.http.client.methods.HttpPost;
|
||||
import org.apache.http.entity.StringEntity;
|
||||
import org.apache.http.impl.client.CloseableHttpClient;
|
||||
import org.apache.http.impl.client.HttpClients;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.Scanner;
|
||||
|
||||
import static com.github.tomakehurst.wiremock.client.WireMock.aResponse;
|
||||
import static com.github.tomakehurst.wiremock.client.WireMock.containing;
|
||||
import static com.github.tomakehurst.wiremock.client.WireMock.equalTo;
|
||||
|
@ -29,16 +15,46 @@ import static com.github.tomakehurst.wiremock.client.WireMock.urlPathMatching;
|
|||
import static com.github.tomakehurst.wiremock.client.WireMock.verify;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.net.ServerSocket;
|
||||
import java.util.Scanner;
|
||||
|
||||
import org.apache.http.HttpResponse;
|
||||
import org.apache.http.client.methods.HttpGet;
|
||||
import org.apache.http.client.methods.HttpPost;
|
||||
import org.apache.http.entity.StringEntity;
|
||||
import org.apache.http.impl.client.CloseableHttpClient;
|
||||
import org.apache.http.impl.client.HttpClients;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import com.github.tomakehurst.wiremock.junit.WireMockRule;
|
||||
|
||||
public class JUnitManagedIntegrationTest {
|
||||
|
||||
private static final String BAELDUNG_WIREMOCK_PATH = "/baeldung/wiremock";
|
||||
private static final String APPLICATION_JSON = "application/json";
|
||||
|
||||
static int port;
|
||||
|
||||
static {
|
||||
|
||||
try {
|
||||
// Get a free port
|
||||
ServerSocket s = new ServerSocket(0);
|
||||
port = s.getLocalPort();
|
||||
s.close();
|
||||
|
||||
} catch (IOException e) {
|
||||
// No OPS
|
||||
}
|
||||
}
|
||||
|
||||
@Rule
|
||||
public WireMockRule wireMockRule = new WireMockRule();
|
||||
public WireMockRule wireMockRule = new WireMockRule(port);
|
||||
|
||||
@Test
|
||||
public void givenJUnitManagedServer_whenMatchingURL_thenCorrect() throws IOException {
|
||||
|
||||
stubFor(get(urlPathMatching("/baeldung/.*"))
|
||||
.willReturn(aResponse()
|
||||
.withStatus(200)
|
||||
|
@ -46,7 +62,7 @@ public class JUnitManagedIntegrationTest {
|
|||
.withBody("\"testing-library\": \"WireMock\"")));
|
||||
|
||||
CloseableHttpClient httpClient = HttpClients.createDefault();
|
||||
HttpGet request = new HttpGet("http://localhost:8080/baeldung/wiremock");
|
||||
HttpGet request = new HttpGet(String.format("http://localhost:%s/baeldung/wiremock", port));
|
||||
HttpResponse httpResponse = httpClient.execute(request);
|
||||
String stringResponse = convertHttpResponseToString(httpResponse);
|
||||
|
||||
|
@ -66,7 +82,7 @@ public class JUnitManagedIntegrationTest {
|
|||
.withBody("!!! Service Unavailable !!!")));
|
||||
|
||||
CloseableHttpClient httpClient = HttpClients.createDefault();
|
||||
HttpGet request = new HttpGet("http://localhost:8080/baeldung/wiremock");
|
||||
HttpGet request = new HttpGet(String.format("http://localhost:%s/baeldung/wiremock", port));
|
||||
request.addHeader("Accept", "text/html");
|
||||
HttpResponse httpResponse = httpClient.execute(request);
|
||||
String stringResponse = convertHttpResponseToString(httpResponse);
|
||||
|
@ -91,7 +107,7 @@ public class JUnitManagedIntegrationTest {
|
|||
StringEntity entity = new StringEntity(jsonString);
|
||||
|
||||
CloseableHttpClient httpClient = HttpClients.createDefault();
|
||||
HttpPost request = new HttpPost("http://localhost:8080/baeldung/wiremock");
|
||||
HttpPost request = new HttpPost(String.format("http://localhost:%s/baeldung/wiremock", port));
|
||||
request.addHeader("Content-Type", APPLICATION_JSON);
|
||||
request.setEntity(entity);
|
||||
HttpResponse response = httpClient.execute(request);
|
||||
|
@ -137,7 +153,7 @@ public class JUnitManagedIntegrationTest {
|
|||
|
||||
private HttpResponse generateClientAndReceiveResponseForPriorityTests() throws IOException {
|
||||
CloseableHttpClient httpClient = HttpClients.createDefault();
|
||||
HttpGet request = new HttpGet("http://localhost:8080/baeldung/wiremock");
|
||||
HttpGet request = new HttpGet(String.format("http://localhost:%s/baeldung/wiremock", port));
|
||||
request.addHeader("Accept", "text/xml");
|
||||
return httpClient.execute(request);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue