All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.lordofthejars.nosqlunit.infinispan.InfinispanOperation Maven / Gradle / Ivy

There is a newer version: 1.0.0
Show newest version
package com.lordofthejars.nosqlunit.infinispan;

import java.io.InputStream;

import org.infinispan.api.BasicCache;

import com.lordofthejars.nosqlunit.core.AbstractCustomizableDatabaseOperation;
import com.lordofthejars.nosqlunit.core.NoSqlAssertionError;

public class InfinispanOperation extends AbstractCustomizableDatabaseOperation> { 

	private BasicCache cache;
	
	
	public InfinispanOperation(BasicCache cache) {
		this.cache = cache;
		setInsertionStrategy(new DefaultInfinispanInsertionStrategy());
		setComparisonStrategy(new DefaultInfinispanComparisonStrategy());
	}
	
	@Override
	public void insert(InputStream dataScript) {
		insertData(dataScript);
	}

	private void insertData(InputStream dataScript) {
		try {
			executeInsertion(new InfinispanConnectionCallback() {
				
				@Override
				public BasicCache basicCache() {
					return cache;
				}
			}, dataScript);
		} catch (Throwable e) {
			throw new IllegalArgumentException(e);
		}
	}

	@Override
	public void deleteAll() {
		this.cache.clear();
	}

	@Override
	public boolean databaseIs(InputStream expectedData) {
		return compareData(expectedData);
	}

	private boolean compareData(InputStream expectedData) throws NoSqlAssertionError {
		try {
			return executeComparison(new InfinispanConnectionCallback() {
				
				@Override
				public BasicCache basicCache() {
					return cache;
				}
			}, expectedData);
		} catch (NoSqlAssertionError e) {
			throw e;
		} catch (Throwable e) {
			throw new IllegalStateException(e);
		}
	}

	@Override
	public BasicCache connectionManager() {
		return this.cache;
	}

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy