BAEL-1734 move packages from libraries to libraries-data
This commit is contained in:
@@ -1,17 +0,0 @@
|
||||
package com.baeldung.hikaricp;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
public class HikariCPIntegrationTest {
|
||||
|
||||
@Test
|
||||
public void givenConnection_thenFetchDbData() {
|
||||
List<Employee> employees = HikariCPDemo.fetchData();
|
||||
assertEquals(4, employees.size());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,42 +0,0 @@
|
||||
package com.baeldung.jcache;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
import javax.cache.Cache;
|
||||
import javax.cache.CacheManager;
|
||||
import javax.cache.Caching;
|
||||
import javax.cache.configuration.FactoryBuilder;
|
||||
import javax.cache.configuration.MutableConfiguration;
|
||||
import javax.cache.spi.CachingProvider;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
public class CacheLoaderTest {
|
||||
|
||||
private static final String CACHE_NAME = "SimpleCache";
|
||||
|
||||
private Cache<Integer, String> cache;
|
||||
|
||||
@Before
|
||||
public void setup() {
|
||||
CachingProvider cachingProvider = Caching.getCachingProvider();
|
||||
CacheManager cacheManager = cachingProvider.getCacheManager();
|
||||
MutableConfiguration<Integer, String> config = new MutableConfiguration<Integer, String>().setReadThrough(true).setCacheLoaderFactory(new FactoryBuilder.SingletonFactory<>(new SimpleCacheLoader()));
|
||||
this.cache = cacheManager.createCache("SimpleCache", config);
|
||||
}
|
||||
|
||||
@After
|
||||
public void tearDown() {
|
||||
Caching.getCachingProvider().getCacheManager().destroyCache(CACHE_NAME);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenReadingFromStorage_thenCorrect() {
|
||||
for (int i = 1; i < 4; i++) {
|
||||
String value = cache.get(i);
|
||||
assertEquals("fromCache" + i, value);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,40 +0,0 @@
|
||||
package com.baeldung.jcache;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import javax.cache.Cache;
|
||||
import javax.cache.CacheManager;
|
||||
import javax.cache.Caching;
|
||||
import javax.cache.configuration.MutableConfiguration;
|
||||
import javax.cache.spi.CachingProvider;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
public class EntryProcessorIntegrationTest {
|
||||
|
||||
private static final String CACHE_NAME = "MyCache";
|
||||
|
||||
private Cache<String, String> cache;
|
||||
|
||||
@Before
|
||||
public void instantiateCache() {
|
||||
CachingProvider cachingProvider = Caching.getCachingProvider();
|
||||
CacheManager cacheManager = cachingProvider.getCacheManager();
|
||||
MutableConfiguration<String, String> config = new MutableConfiguration<>();
|
||||
this.cache = cacheManager.createCache(CACHE_NAME, config);
|
||||
this.cache.put("key", "value");
|
||||
}
|
||||
|
||||
@After
|
||||
public void tearDown() {
|
||||
Caching.getCachingProvider().getCacheManager().destroyCache(CACHE_NAME);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenModifyValue_thenCorrect() {
|
||||
this.cache.invoke("key", new SimpleEntryProcessor());
|
||||
assertEquals("value - modified", cache.get("key"));
|
||||
}
|
||||
}
|
||||
@@ -1,54 +0,0 @@
|
||||
package com.baeldung.jcache;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import javax.cache.Cache;
|
||||
import javax.cache.CacheManager;
|
||||
import javax.cache.Caching;
|
||||
import javax.cache.configuration.FactoryBuilder;
|
||||
import javax.cache.configuration.MutableCacheEntryListenerConfiguration;
|
||||
import javax.cache.configuration.MutableConfiguration;
|
||||
import javax.cache.spi.CachingProvider;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
public class EventListenerIntegrationTest {
|
||||
|
||||
private static final String CACHE_NAME = "MyCache";
|
||||
|
||||
private Cache<String, String> cache;
|
||||
private SimpleCacheEntryListener listener;
|
||||
private MutableCacheEntryListenerConfiguration<String, String> listenerConfiguration;
|
||||
|
||||
@Before
|
||||
public void setup() {
|
||||
CachingProvider cachingProvider = Caching.getCachingProvider();
|
||||
CacheManager cacheManager = cachingProvider.getCacheManager();
|
||||
MutableConfiguration<String, String> config = new MutableConfiguration<String, String>();
|
||||
this.cache = cacheManager.createCache("MyCache", config);
|
||||
this.listener = new SimpleCacheEntryListener();
|
||||
}
|
||||
|
||||
@After
|
||||
public void tearDown() {
|
||||
Caching.getCachingProvider().getCacheManager().destroyCache(CACHE_NAME);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenRunEvent_thenCorrect() throws InterruptedException {
|
||||
this.listenerConfiguration = new MutableCacheEntryListenerConfiguration<>(FactoryBuilder.factoryOf(this.listener), null, false, true);
|
||||
this.cache.registerCacheEntryListener(this.listenerConfiguration);
|
||||
|
||||
assertEquals(false, this.listener.getCreated());
|
||||
|
||||
this.cache.put("key", "value");
|
||||
assertEquals(true, this.listener.getCreated());
|
||||
assertEquals(false, this.listener.getUpdated());
|
||||
|
||||
this.cache.put("key", "newValue");
|
||||
assertEquals(true, this.listener.getUpdated());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,27 +0,0 @@
|
||||
package com.baeldung.jcache;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import javax.cache.Cache;
|
||||
import javax.cache.CacheManager;
|
||||
import javax.cache.Caching;
|
||||
import javax.cache.configuration.MutableConfiguration;
|
||||
import javax.cache.spi.CachingProvider;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
public class JCacheIntegrationTest {
|
||||
|
||||
@Test
|
||||
public void instantiateCache() {
|
||||
CachingProvider cachingProvider = Caching.getCachingProvider();
|
||||
CacheManager cacheManager = cachingProvider.getCacheManager();
|
||||
MutableConfiguration<String, String> config = new MutableConfiguration<>();
|
||||
Cache<String, String> cache = cacheManager.createCache("simpleCache", config);
|
||||
cache.put("key1", "value1");
|
||||
cache.put("key2", "value2");
|
||||
assertEquals("value1", cache.get("key1"));
|
||||
assertEquals("value2", cache.get("key2"));
|
||||
cacheManager.close();
|
||||
}
|
||||
}
|
||||
@@ -1,109 +0,0 @@
|
||||
package com.baeldung.jdo;
|
||||
|
||||
import org.datanucleus.api.jdo.JDOPersistenceManagerFactory;
|
||||
import org.datanucleus.metadata.PersistenceUnitMetaData;
|
||||
import org.junit.Test;
|
||||
|
||||
import javax.jdo.PersistenceManager;
|
||||
import javax.jdo.PersistenceManagerFactory;
|
||||
import javax.jdo.Query;
|
||||
import javax.jdo.Transaction;
|
||||
import java.util.List;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
public class GuideToJDOIntegrationTest {
|
||||
@Test
|
||||
public void givenProduct_WhenNewThenPerformTransaction() {
|
||||
PersistenceUnitMetaData pumd = new PersistenceUnitMetaData("dynamic-unit", "RESOURCE_LOCAL", null);
|
||||
pumd.addClassName("com.baeldung.jdo.Product");
|
||||
pumd.setExcludeUnlistedClasses();
|
||||
pumd.addProperty("javax.jdo.option.ConnectionDriverName", "org.h2.Driver");
|
||||
pumd.addProperty("javax.jdo.option.ConnectionURL", "jdbc:h2:mem:mypersistence");
|
||||
pumd.addProperty("javax.jdo.option.ConnectionUserName", "sa");
|
||||
pumd.addProperty("javax.jdo.option.ConnectionPassword", "");
|
||||
pumd.addProperty("datanucleus.autoCreateSchema", "true");
|
||||
|
||||
PersistenceManagerFactory pmf = new JDOPersistenceManagerFactory(pumd, null);
|
||||
PersistenceManager pm = pmf.getPersistenceManager();
|
||||
Transaction tx = pm.currentTransaction();
|
||||
try {
|
||||
tx.begin();
|
||||
for (int i = 0; i < 100; i++) {
|
||||
String nam = "Product-" + i;
|
||||
Product productx = new Product(nam, (double) i);
|
||||
pm.makePersistent(productx);
|
||||
}
|
||||
tx.commit();
|
||||
} catch (Throwable thr) {
|
||||
fail("Failed test : " + thr.getMessage());
|
||||
} finally {
|
||||
if (tx.isActive()) {
|
||||
tx.rollback();
|
||||
}
|
||||
pm.close();
|
||||
}
|
||||
|
||||
pmf.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenProduct_WhenQueryThenExist() {
|
||||
PersistenceUnitMetaData pumd = new PersistenceUnitMetaData("dynamic-unit", "RESOURCE_LOCAL", null);
|
||||
pumd.addClassName("com.baeldung.jdo.Product");
|
||||
pumd.setExcludeUnlistedClasses();
|
||||
pumd.addProperty("javax.jdo.option.ConnectionDriverName", "org.h2.Driver");
|
||||
pumd.addProperty("javax.jdo.option.ConnectionURL", "jdbc:h2:mem:mypersistence");
|
||||
pumd.addProperty("javax.jdo.option.ConnectionUserName", "sa");
|
||||
pumd.addProperty("javax.jdo.option.ConnectionPassword", "");
|
||||
pumd.addProperty("datanucleus.autoCreateSchema", "true");
|
||||
|
||||
PersistenceManagerFactory pmf = new JDOPersistenceManagerFactory(pumd, null);
|
||||
PersistenceManager pm = pmf.getPersistenceManager();
|
||||
Transaction tx = pm.currentTransaction();
|
||||
try {
|
||||
tx.begin();
|
||||
Product product = new Product("Tablet", 80.0);
|
||||
pm.makePersistent(product);
|
||||
Product product2 = new Product("Phone", 20.0);
|
||||
pm.makePersistent(product2);
|
||||
Product product3 = new Product("Laptop", 200.0);
|
||||
pm.makePersistent(product3);
|
||||
tx.commit();
|
||||
} catch (Throwable thr) {
|
||||
fail("Failed test : " + thr.getMessage());
|
||||
} finally {
|
||||
if (tx.isActive()) {
|
||||
tx.rollback();
|
||||
}
|
||||
pm.close();
|
||||
}
|
||||
|
||||
pmf.close();
|
||||
|
||||
PersistenceManagerFactory pmf2 = new JDOPersistenceManagerFactory(pumd, null);
|
||||
PersistenceManager pm2 = pmf2.getPersistenceManager();
|
||||
Transaction tx2 = pm2.currentTransaction();
|
||||
try {
|
||||
tx2.begin();
|
||||
|
||||
@SuppressWarnings("rawtypes")
|
||||
Query q = pm2.newQuery("SELECT FROM " + Product.class.getName() + " WHERE price == 200");
|
||||
@SuppressWarnings("unchecked")
|
||||
List<Product> products = (List<Product>) q.execute();
|
||||
for (Product p : products) {
|
||||
assertEquals("Laptop", p.name);
|
||||
}
|
||||
|
||||
tx2.commit();
|
||||
} finally {
|
||||
if (tx2.isActive()) {
|
||||
tx2.rollback();
|
||||
}
|
||||
|
||||
pm2.close();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user