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:
Amit Pandey 2018-06-11 13:48:30 +05:30 committed by Grzegorz Piwowarek
parent 096826cc07
commit a54c9e0c9e
40 changed files with 201 additions and 101 deletions

View File

@ -1,15 +1,17 @@
package com.baeldung.poi.powerpoint; 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.XMLSlideShow;
import org.apache.poi.xslf.usermodel.XSLFShape; import org.apache.poi.xslf.usermodel.XSLFShape;
import org.apache.poi.xslf.usermodel.XSLFSlide; import org.apache.poi.xslf.usermodel.XSLFSlide;
import org.junit.After; import org.junit.After;
import org.junit.Assert; import org.junit.Assert;
import org.junit.Before; import org.junit.Before;
import org.junit.Rule;
import org.junit.Test; import org.junit.Test;
import org.junit.rules.TemporaryFolder;
import java.io.File;
import java.util.List;
public class PowerPointIntegrationTest { public class PowerPointIntegrationTest {
@ -17,9 +19,12 @@ public class PowerPointIntegrationTest {
private String fileLocation; private String fileLocation;
private static final String FILE_NAME = "presentation.pptx"; private static final String FILE_NAME = "presentation.pptx";
@Rule
public TemporaryFolder tempFolder = new TemporaryFolder();
@Before @Before
public void setUp() throws Exception { public void setUp() throws Exception {
File currDir = new File("."); File currDir = tempFolder.newFolder();
String path = currDir.getAbsolutePath(); String path = currDir.getAbsolutePath();
fileLocation = path.substring(0, path.length() - 1) + FILE_NAME; fileLocation = path.substring(0, path.length() - 1) + FILE_NAME;

View File

@ -46,7 +46,7 @@ public class JaggedArrayUnitTest {
ByteArrayOutputStream outContent = new ByteArrayOutputStream(); ByteArrayOutputStream outContent = new ByteArrayOutputStream();
System.setOut(new PrintStream(outContent)); System.setOut(new PrintStream(outContent));
obj.printElements(jaggedArr); 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); System.setOut(System.out);
} }

View File

@ -179,7 +179,7 @@ public class JavaMoneyUnitManualTest {
MonetaryAmountFormat customFormat = MonetaryFormats.getAmountFormat(AmountFormatQueryBuilder MonetaryAmountFormat customFormat = MonetaryFormats.getAmountFormat(AmountFormatQueryBuilder
.of(Locale.US) .of(Locale.US)
.set(CurrencyStyle.NAME) .set(CurrencyStyle.NAME)
.set("pattern", "00000.00 <EFBFBD>") .set("pattern", "00000.00 US Dollar")
.build()); .build());
String customFormatted = customFormat.format(oneDollar); String customFormatted = customFormat.format(oneDollar);

View File

@ -104,7 +104,7 @@ public class NashornUnitTest {
public void loadExamples() throws ScriptException { public void loadExamples() throws ScriptException {
Object loadResult = engine.eval("load('classpath:js/script.js');" + "increment(5)"); 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);"); Object math = engine.eval("var math = loadWithNewGlobal('classpath:js/math_module.js');" + "math.increment(5);");

View File

@ -5,6 +5,7 @@ import java.util.concurrent.ConcurrentHashMap;
import javax.annotation.PostConstruct; import javax.annotation.PostConstruct;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import com.couchbase.client.java.Bucket; import com.couchbase.client.java.Bucket;
@ -19,6 +20,11 @@ public class ClusterServiceImpl implements ClusterService {
private Cluster cluster; private Cluster cluster;
private Map<String, Bucket> buckets = new ConcurrentHashMap<>(); private Map<String, Bucket> buckets = new ConcurrentHashMap<>();
@Autowired
public ClusterServiceImpl(Cluster cluster) {
this.cluster = cluster;
}
@PostConstruct @PostConstruct
private void init() { private void init() {
CouchbaseEnvironment env = DefaultCouchbaseEnvironment.create(); CouchbaseEnvironment env = DefaultCouchbaseEnvironment.create();

View File

@ -18,6 +18,7 @@ public class TutorialBucketService extends AbstractBucketService {
@Autowired @Autowired
public TutorialBucketService(ClusterService clusterService) { public TutorialBucketService(ClusterService clusterService) {
super(clusterService); super(clusterService);
openBucket();
} }
@Override @Override

View File

@ -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");
}
}

View File

@ -1,27 +1,31 @@
package com.baeldung.couchbase.async.person; 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.ArrayList;
import java.util.List; import java.util.List;
import java.util.UUID; import java.util.UUID;
import javax.annotation.PostConstruct;
import org.apache.commons.lang3.RandomStringUtils; import org.apache.commons.lang3.RandomStringUtils;
import org.junit.Before;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier; 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.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.baeldung.couchbase.async.service.BucketService;
import com.couchbase.client.java.Bucket; import com.couchbase.client.java.Bucket;
import com.couchbase.client.java.document.JsonDocument; 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 @Autowired
private PersonCrudService personService; private PersonCrudService personService;
@ -35,8 +39,8 @@ public class PersonCrudServiceIntegrationTest extends AsyncIntegrationTest {
private Bucket bucket; private Bucket bucket;
@PostConstruct @Before
private void init() { public void init() {
bucket = bucketService.getBucket(); bucket = bucketService.getBucket();
} }

View File

@ -18,7 +18,7 @@ import com.couchbase.client.java.Bucket;
@RunWith(SpringJUnit4ClassRunner.class) @RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(classes = { AsyncIntegrationTestConfig.class }) @ContextConfiguration(classes = { AsyncIntegrationTestConfig.class })
@TestExecutionListeners(listeners = { DependencyInjectionTestExecutionListener.class }) @TestExecutionListeners(listeners = { DependencyInjectionTestExecutionListener.class })
public class ClusterServiceIntegrationTest extends AsyncIntegrationTest { public class ClusterServiceLiveTest extends AsyncIntegrationTest {
@Autowired @Autowired
private ClusterService couchbaseService; private ClusterService couchbaseService;

View File

@ -14,8 +14,8 @@ import com.couchbase.client.java.document.JsonDocument;
import com.couchbase.client.java.view.ViewResult; import com.couchbase.client.java.view.ViewResult;
import com.couchbase.client.java.view.ViewRow; import com.couchbase.client.java.view.ViewRow;
public class StudentGradeServiceIntegrationTest { public class StudentGradeServiceLiveTest {
private static final Logger logger = LoggerFactory.getLogger(StudentGradeServiceIntegrationTest.class); private static final Logger logger = LoggerFactory.getLogger(StudentGradeServiceLiveTest.class);
static StudentGradeService studentGradeService; static StudentGradeService studentGradeService;
static Set<String> gradeIds = new HashSet<>(); static Set<String> gradeIds = new HashSet<>();

View File

@ -1,5 +1,23 @@
package com.baeldung.couchbase.n1ql; 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.Bucket;
import com.couchbase.client.java.Cluster; import com.couchbase.client.java.Cluster;
import com.couchbase.client.java.document.JsonDocument; 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.N1qlQueryRow;
import com.couchbase.client.java.query.Statement; import com.couchbase.client.java.query.Statement;
import com.fasterxml.jackson.databind.JsonNode; 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 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) @RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(classes = { IntegrationTestConfig.class }) @ContextConfiguration(classes = { IntegrationTestConfig.class })
public class N1QLIntegrationTest { public class N1QLLiveTest {
@Autowired @Autowired

View File

@ -10,7 +10,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import com.baeldung.couchbase.spring.IntegrationTest; 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 CLARK_KENT = "Clark Kent";
private static final String SMALLVILLE = "Smallville"; private static final String SMALLVILLE = "Smallville";

View File

@ -17,7 +17,7 @@ import com.couchbase.client.java.Bucket;
@RunWith(SpringJUnit4ClassRunner.class) @RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(classes = { IntegrationTestConfig.class }) @ContextConfiguration(classes = { IntegrationTestConfig.class })
@TestExecutionListeners(listeners = { DependencyInjectionTestExecutionListener.class }) @TestExecutionListeners(listeners = { DependencyInjectionTestExecutionListener.class })
public class ClusterServiceIntegrationTest extends IntegrationTest { public class ClusterServiceLiveTest extends IntegrationTest {
@Autowired @Autowired
private ClusterService couchbaseService; private ClusterService couchbaseService;

View File

@ -39,6 +39,11 @@
<artifactId>commons-lang3</artifactId> <artifactId>commons-lang3</artifactId>
<version>${commons-lang3.version}</version> <version>${commons-lang3.version}</version>
</dependency> </dependency>
<dependency>
<groupId>javax.activation</groupId>
<artifactId>activation</artifactId>
<version>1.1</version>
</dependency>
</dependencies> </dependencies>
<build> <build>

View File

@ -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

View File

@ -44,7 +44,7 @@ public class JaxbIntegrationTest {
File bookFile = new File(this.getClass().getResource("/book.xml").getFile()); File bookFile = new File(this.getClass().getResource("/book.xml").getFile());
String sampleBookXML = FileUtils.readFileToString(sampleBookFile, "UTF-8"); String sampleBookXML = FileUtils.readFileToString(sampleBookFile, "UTF-8");
String marshallerBookXML = FileUtils.readFileToString(bookFile, "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 @Test

View File

@ -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>

View File

@ -22,7 +22,7 @@ import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.FindBy; import org.openqa.selenium.support.FindBy;
@RunWith(Arquillian.class) @RunWith(Arquillian.class)
public class ConvListValIntegrationTest { public class ConvListValLiveTest {
@ArquillianResource @ArquillianResource
private URL deploymentUrl; private URL deploymentUrl;

View File

@ -21,7 +21,7 @@ import static org.hamcrest.Matchers.equalTo;
@RunWith(Arquillian.class) @RunWith(Arquillian.class)
public class AutomaticTimerBeanIntegrationTest { public class AutomaticTimerBeanLiveTest {
//the @AutomaticTimerBean has a method called every 10 seconds //the @AutomaticTimerBean has a method called every 10 seconds
//testing the difference ==> 100000 //testing the difference ==> 100000

View File

@ -21,7 +21,7 @@ import static org.hamcrest.Matchers.is;
@RunWith(Arquillian.class) @RunWith(Arquillian.class)
public class ProgrammaticAtFixedRateTimerBeanIntegrationTest { public class ProgrammaticAtFixedRateTimerBeanLiveTest {
final static long TIMEOUT = 1000; final static long TIMEOUT = 1000;
final static long TOLERANCE = 500l; final static long TOLERANCE = 500l;

View File

@ -19,7 +19,7 @@ import static org.hamcrest.Matchers.is;
@RunWith(Arquillian.class) @RunWith(Arquillian.class)
public class ProgrammaticTimerBeanIntegrationTest { public class ProgrammaticTimerBeanLiveTest {
final static long TIMEOUT = 5000l; final static long TIMEOUT = 5000l;
final static long TOLERANCE = 1000l; final static long TOLERANCE = 1000l;

View File

@ -21,7 +21,7 @@ import static org.hamcrest.Matchers.is;
@RunWith(Arquillian.class) @RunWith(Arquillian.class)
public class ProgrammaticWithFixedDelayTimerBeanIntegrationTest { public class ProgrammaticWithFixedDelayTimerBeanLiveTest {
final static long TIMEOUT = 15000l; final static long TIMEOUT = 15000l;
final static long TOLERANCE = 1000l; final static long TOLERANCE = 1000l;

View File

@ -20,7 +20,7 @@ import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.equalTo;
@RunWith(Arquillian.class) @RunWith(Arquillian.class)
public class ScheduleTimerBeanIntegrationTest { public class ScheduleTimerBeanLiveTest {
private final static long TIMEOUT = 5000l; private final static long TIMEOUT = 5000l;
private final static long TOLERANCE = 1000l; private final static long TOLERANCE = 1000l;

View File

@ -15,7 +15,7 @@ import org.junit.Test;
import com.baeldung.jpa.model.Car; import com.baeldung.jpa.model.Car;
public class StoredProcedureIntegrationTest { public class StoredProcedureLiveTest {
private static EntityManagerFactory factory = null; private static EntityManagerFactory factory = null;
private static EntityManager entityManager = null; private static EntityManager entityManager = null;

View File

@ -15,12 +15,13 @@ import static org.junit.Assert.assertEquals;
public class EntryProcessorIntegrationTest { public class EntryProcessorIntegrationTest {
private static final String CACHE_NAME = "MyCache"; private static final String CACHE_NAME = "MyCache";
private static final String CACHE_PROVIDER_NAME = "com.hazelcast.cache.HazelcastCachingProvider";
private Cache<String, String> cache; private Cache<String, String> cache;
@Before @Before
public void instantiateCache() { public void instantiateCache() {
CachingProvider cachingProvider = Caching.getCachingProvider(); CachingProvider cachingProvider = Caching.getCachingProvider(CACHE_PROVIDER_NAME);
CacheManager cacheManager = cachingProvider.getCacheManager(); CacheManager cacheManager = cachingProvider.getCacheManager();
MutableConfiguration<String, String> config = new MutableConfiguration<>(); MutableConfiguration<String, String> config = new MutableConfiguration<>();
this.cache = cacheManager.createCache(CACHE_NAME, config); this.cache = cacheManager.createCache(CACHE_NAME, config);
@ -29,7 +30,7 @@ public class EntryProcessorIntegrationTest {
@After @After
public void tearDown() { public void tearDown() {
Caching.getCachingProvider().getCacheManager().destroyCache(CACHE_NAME); Caching.getCachingProvider(CACHE_PROVIDER_NAME).getCacheManager().destroyCache(CACHE_NAME);
} }
@Test @Test

View File

@ -17,6 +17,7 @@ import static org.junit.Assert.assertEquals;
public class EventListenerIntegrationTest { public class EventListenerIntegrationTest {
private static final String CACHE_NAME = "MyCache"; private static final String CACHE_NAME = "MyCache";
private static final String CACHE_PROVIDER_NAME = "com.hazelcast.cache.HazelcastCachingProvider";
private Cache<String, String> cache; private Cache<String, String> cache;
private SimpleCacheEntryListener listener; private SimpleCacheEntryListener listener;
@ -24,7 +25,7 @@ public class EventListenerIntegrationTest {
@Before @Before
public void setup() { public void setup() {
CachingProvider cachingProvider = Caching.getCachingProvider(); CachingProvider cachingProvider = Caching.getCachingProvider(CACHE_PROVIDER_NAME);
CacheManager cacheManager = cachingProvider.getCacheManager(); CacheManager cacheManager = cachingProvider.getCacheManager();
MutableConfiguration<String, String> config = new MutableConfiguration<String, String>(); MutableConfiguration<String, String> config = new MutableConfiguration<String, String>();
this.cache = cacheManager.createCache("MyCache", config); this.cache = cacheManager.createCache("MyCache", config);
@ -33,7 +34,7 @@ public class EventListenerIntegrationTest {
@After @After
public void tearDown() { public void tearDown() {
Caching.getCachingProvider().getCacheManager().destroyCache(CACHE_NAME); Caching.getCachingProvider(CACHE_PROVIDER_NAME).getCacheManager().destroyCache(CACHE_NAME);
} }
@Test @Test

View File

@ -14,7 +14,7 @@ public class JCacheIntegrationTest {
@Test @Test
public void instantiateCache() { public void instantiateCache() {
CachingProvider cachingProvider = Caching.getCachingProvider(); CachingProvider cachingProvider = Caching.getCachingProvider("com.hazelcast.cache.HazelcastCachingProvider");
CacheManager cacheManager = cachingProvider.getCacheManager(); CacheManager cacheManager = cachingProvider.getCacheManager();
MutableConfiguration<String, String> config = new MutableConfiguration<>(); MutableConfiguration<String, String> config = new MutableConfiguration<>();
Cache<String, String> cache = cacheManager.createCache("simpleCache", config); Cache<String, String> cache = cacheManager.createCache("simpleCache", config);

View File

@ -2,6 +2,6 @@
<ConnectionManager className="com.gs.fw.common.mithra.test.ConnectionManagerForTests"> <ConnectionManager className="com.gs.fw.common.mithra.test.ConnectionManagerForTests">
<Property name="resourceName" value="testDb"/> <Property name="resourceName" value="testDb"/>
<MithraObjectConfiguration className="com.baeldung.reladomo.Department" cacheType="partial"/> <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> </ConnectionManager>
</MithraRuntime> </MithraRuntime>

View File

@ -12,6 +12,7 @@ import org.apache.logging.log4j.Logger;
import org.junit.Before; import org.junit.Before;
import org.junit.Test; import org.junit.Test;
import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.ObjectMapper;
public class JSONLayoutIntegrationTest extends Log4j2BaseIntegrationTest { public class JSONLayoutIntegrationTest extends Log4j2BaseIntegrationTest {

View File

@ -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

View File

@ -27,7 +27,9 @@ public class RedissonConfigurationIntegrationTest {
@AfterClass @AfterClass
public static void destroy() { public static void destroy() {
redisServer.stop(); redisServer.stop();
client.shutdown(); if (client != null) {
client.shutdown();
}
} }
@Test @Test

View File

@ -37,7 +37,9 @@ public class RedissonIntegrationTest {
@AfterClass @AfterClass
public static void destroy() { public static void destroy() {
redisServer.stop(); redisServer.stop();
client.shutdown(); if (client != null) {
client.shutdown();
}
} }
@Test @Test

View File

@ -18,26 +18,27 @@ public class AutomapInterfaceIntegrationTest {
private ConnectionProvider connectionProvider = Connector.connectionProvider; private ConnectionProvider connectionProvider = Connector.connectionProvider;
private Database db = Database.from(connectionProvider); private Database db = Database.from(connectionProvider);
private Observable<Integer> create = null; private Observable<Integer> truncate = null;
private Observable<Integer> insert1, insert2 = null; private Observable<Integer> insert1, insert2 = null;
@Before @Before
public void setup() { 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(); .count();
truncate = db.update("TRUNCATE TABLE EMPLOYEE")
.dependsOn(create)
.count();
insert1 = db.update("INSERT INTO EMPLOYEE(id, name) VALUES(1, 'Alan')") insert1 = db.update("INSERT INTO EMPLOYEE(id, name) VALUES(1, 'Alan')")
.dependsOn(create) .dependsOn(truncate)
.count(); .count();
insert2 = db.update("INSERT INTO EMPLOYEE(id, name) VALUES(2, 'Sarah')") insert2 = db.update("INSERT INTO EMPLOYEE(id, name) VALUES(2, 'Sarah')")
.dependsOn(create) .dependsOn(insert1)
.count(); .count();
} }
@Test @Test
public void whenSelectFromTableAndAutomap_thenCorrect() { public void whenSelectFromTableAndAutomap_thenCorrect() {
List<Employee> employees = db.select("select id, name from EMPLOYEE") List<Employee> employees = db.select("select id, name from EMPLOYEE")
.dependsOn(create)
.dependsOn(insert1)
.dependsOn(insert2) .dependsOn(insert2)
.autoMap(Employee.class) .autoMap(Employee.class)
.toList() .toList()
@ -57,7 +58,7 @@ public class AutomapInterfaceIntegrationTest {
@After @After
public void close() { public void close() {
db.update("DROP TABLE EMPLOYEE") db.update("DROP TABLE EMPLOYEE")
.dependsOn(create); .dependsOn(truncate);
connectionProvider.close(); connectionProvider.close();
} }
} }

View File

@ -22,24 +22,24 @@ public class BasicQueryTypesIntegrationTest {
@Test @Test
public void whenCreateTableAndInsertRecords_thenCorrect() { 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(); .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) .dependsOn(create)
.count(); .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) .dependsOn(create)
.count(); .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) .dependsOn(create)
.count(); .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) .dependsOn(create)
.count(); .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) .dependsOn(create)
.count(); .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) .parameter(3)
.dependsOn(create) .dependsOn(create)
.dependsOn(insert1) .dependsOn(insert1)
@ -57,7 +57,7 @@ public class BasicQueryTypesIntegrationTest {
@After @After
public void close() { public void close() {
db.update("DROP TABLE EMPLOYEE") db.update("DROP TABLE EMPLOYEE_TABLE")
.dependsOn(create); .dependsOn(create);
connectionProvider.close(); connectionProvider.close();
} }

View File

@ -27,7 +27,7 @@ public class InsertClobIntegrationTest {
@Before @Before
public void setup() throws IOException { 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(); .count();
InputStream actualInputStream = new FileInputStream("src/test/resources/actual_clob"); 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"); InputStream expectedInputStream = new FileInputStream("src/test/resources/expected_clob");
this.expectedDocument = Utils.getStringFromInputStream(expectedInputStream); 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(1)
.parameter(Database.toSentinelIfNull(actualDocument)) .parameter(Database.toSentinelIfNull(actualDocument))
.dependsOn(create) .dependsOn(create)
@ -44,7 +44,7 @@ public class InsertClobIntegrationTest {
@Test @Test
public void whenSelectCLOB_thenCorrect() throws IOException { 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(create)
.dependsOn(insert) .dependsOn(insert)
.getAs(String.class) .getAs(String.class)
@ -56,7 +56,7 @@ public class InsertClobIntegrationTest {
@After @After
public void close() { public void close() {
db.update("DROP TABLE SERVERLOG") db.update("DROP TABLE SERVERLOG_TABLE")
.dependsOn(create); .dependsOn(create);
connectionProvider.close(); connectionProvider.close();
} }

View File

@ -22,14 +22,14 @@ public class ReturnKeysIntegrationTest {
@Before @Before
public void setup() { public void setup() {
begin = db.beginTransaction(); 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) .dependsOn(begin)
.count(); .count();
} }
@Test @Test
public void whenInsertAndReturnGeneratedKey_thenCorrect() { 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) .dependsOn(createStatement)
.returnGeneratedKeys() .returnGeneratedKeys()
.getAs(Integer.class) .getAs(Integer.class)
@ -41,7 +41,7 @@ public class ReturnKeysIntegrationTest {
@After @After
public void close() { public void close() {
db.update("DROP TABLE EMPLOYEE") db.update("DROP TABLE EMPLOYEE_SAMPLE")
.dependsOn(createStatement); .dependsOn(createStatement);
connectionProvider.close(); connectionProvider.close();
} }

View File

@ -24,8 +24,11 @@ public class TransactionIntegrationTest {
.update("CREATE TABLE IF NOT EXISTS EMPLOYEE(id int primary key, name varchar(255))") .update("CREATE TABLE IF NOT EXISTS EMPLOYEE(id int primary key, name varchar(255))")
.dependsOn(begin) .dependsOn(begin)
.count(); .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')") Observable<Integer> insertStatement = db.update("INSERT INTO EMPLOYEE(id, name) VALUES(1, 'John')")
.dependsOn(createStatement) .dependsOn(truncateStatement)
.count(); .count();
Observable<Integer> updateStatement = db.update("UPDATE EMPLOYEE SET name = 'Tom' WHERE id = 1") Observable<Integer> updateStatement = db.update("UPDATE EMPLOYEE SET name = 'Tom' WHERE id = 1")
.dependsOn(insertStatement) .dependsOn(insertStatement)

View File

@ -7,6 +7,8 @@ import org.powermock.core.classloader.annotations.PrepareForTest;
import org.powermock.modules.junit4.PowerMockRunner; import org.powermock.modules.junit4.PowerMockRunner;
import static org.junit.Assert.assertEquals; 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.*; import static org.powermock.api.mockito.PowerMockito.*;
@RunWith(PowerMockRunner.class) @RunWith(PowerMockRunner.class)
@ -23,7 +25,7 @@ public class PowerMockitoIntegrationTest {
when(collaborator.helloMethod()).thenReturn("Hello Baeldung!"); when(collaborator.helloMethod()).thenReturn("Hello Baeldung!");
String welcome = collaborator.helloMethod(); String welcome = collaborator.helloMethod();
Mockito.verify(collaborator).helloMethod(); verify(collaborator).helloMethod();
assertEquals("Hello Baeldung!", welcome); assertEquals("Hello Baeldung!", welcome);
} }
@ -42,7 +44,7 @@ public class PowerMockitoIntegrationTest {
assertEquals("Hello Baeldung!", firstWelcome); assertEquals("Hello Baeldung!", firstWelcome);
assertEquals("Hello Baeldung!", secondWelcome); assertEquals("Hello Baeldung!", secondWelcome);
verifyStatic(Mockito.times(2)); verifyStatic(times(2));
CollaboratorWithStaticMethods.firstMethod(Mockito.anyString()); CollaboratorWithStaticMethods.firstMethod(Mockito.anyString());
verifyStatic(Mockito.never()); verifyStatic(Mockito.never());
@ -67,7 +69,7 @@ public class PowerMockitoIntegrationTest {
when(mock.finalMethod()).thenReturn("I am a final mock method."); when(mock.finalMethod()).thenReturn("I am a final mock method.");
returnValue = mock.finalMethod(); returnValue = mock.finalMethod();
Mockito.verify(mock).finalMethod(); verify(mock,times(3)).finalMethod();
assertEquals("I am a final mock method.", returnValue); assertEquals("I am a final mock method.", returnValue);
when(mock, "privateMethod").thenReturn("I am a private mock method."); when(mock, "privateMethod").thenReturn("I am a private mock method.");

View File

@ -24,7 +24,7 @@ public class MockitoMockIntegrationTest {
} }
@Rule @Rule
private ExpectedException thrown = ExpectedException.none(); public ExpectedException thrown = ExpectedException.none();
@Test @Test
public void whenUsingSimpleMock_thenCorrect() { public void whenUsingSimpleMock_thenCorrect() {

View File

@ -1,19 +1,5 @@
package com.baeldung.rest.wiremock.introduction; 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.aResponse;
import static com.github.tomakehurst.wiremock.client.WireMock.containing; import static com.github.tomakehurst.wiremock.client.WireMock.containing;
import static com.github.tomakehurst.wiremock.client.WireMock.equalTo; 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 com.github.tomakehurst.wiremock.client.WireMock.verify;
import static org.junit.Assert.assertEquals; 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 { public class JUnitManagedIntegrationTest {
private static final String BAELDUNG_WIREMOCK_PATH = "/baeldung/wiremock"; private static final String BAELDUNG_WIREMOCK_PATH = "/baeldung/wiremock";
private static final String APPLICATION_JSON = "application/json"; 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 @Rule
public WireMockRule wireMockRule = new WireMockRule(); public WireMockRule wireMockRule = new WireMockRule(port);
@Test @Test
public void givenJUnitManagedServer_whenMatchingURL_thenCorrect() throws IOException { public void givenJUnitManagedServer_whenMatchingURL_thenCorrect() throws IOException {
stubFor(get(urlPathMatching("/baeldung/.*")) stubFor(get(urlPathMatching("/baeldung/.*"))
.willReturn(aResponse() .willReturn(aResponse()
.withStatus(200) .withStatus(200)
@ -46,7 +62,7 @@ public class JUnitManagedIntegrationTest {
.withBody("\"testing-library\": \"WireMock\""))); .withBody("\"testing-library\": \"WireMock\"")));
CloseableHttpClient httpClient = HttpClients.createDefault(); 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); HttpResponse httpResponse = httpClient.execute(request);
String stringResponse = convertHttpResponseToString(httpResponse); String stringResponse = convertHttpResponseToString(httpResponse);
@ -66,7 +82,7 @@ public class JUnitManagedIntegrationTest {
.withBody("!!! Service Unavailable !!!"))); .withBody("!!! Service Unavailable !!!")));
CloseableHttpClient httpClient = HttpClients.createDefault(); 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"); request.addHeader("Accept", "text/html");
HttpResponse httpResponse = httpClient.execute(request); HttpResponse httpResponse = httpClient.execute(request);
String stringResponse = convertHttpResponseToString(httpResponse); String stringResponse = convertHttpResponseToString(httpResponse);
@ -91,7 +107,7 @@ public class JUnitManagedIntegrationTest {
StringEntity entity = new StringEntity(jsonString); StringEntity entity = new StringEntity(jsonString);
CloseableHttpClient httpClient = HttpClients.createDefault(); 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.addHeader("Content-Type", APPLICATION_JSON);
request.setEntity(entity); request.setEntity(entity);
HttpResponse response = httpClient.execute(request); HttpResponse response = httpClient.execute(request);
@ -137,7 +153,7 @@ public class JUnitManagedIntegrationTest {
private HttpResponse generateClientAndReceiveResponseForPriorityTests() throws IOException { private HttpResponse generateClientAndReceiveResponseForPriorityTests() throws IOException {
CloseableHttpClient httpClient = HttpClients.createDefault(); 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"); request.addHeader("Accept", "text/xml");
return httpClient.execute(request); return httpClient.execute(request);
} }