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

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

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

import org.junit.rules.ExternalResource;

public class ManagedInfinispan extends ExternalResource {

	protected ManagedInfinispanLifecycleManager managedInfinispanLifecycleManager;
	
	private ManagedInfinispan() {
		super();
	}
	
	public static class ManagedInfinispanRuleBuilder {
		
		private ManagedInfinispanLifecycleManager managedInfinispanLifecycleManager;
		
		private ManagedInfinispanRuleBuilder() {
			this.managedInfinispanLifecycleManager = new ManagedInfinispanLifecycleManager();
		}
		
		public static ManagedInfinispanRuleBuilder newManagedInfinispanRule() {
			return new ManagedInfinispanRuleBuilder();
		}
		
		public ManagedInfinispanRuleBuilder port(int port) {
			this.managedInfinispanLifecycleManager.setPort(port);
			return this;
		}
		
		public ManagedInfinispanRuleBuilder targetPath(String targetPath) {
			this.managedInfinispanLifecycleManager.setTargetPath(targetPath);
			return this;
		}
		
		public ManagedInfinispanRuleBuilder infinispanPath(String infinispanPath) {
			this.managedInfinispanLifecycleManager.setInfinispanPath(infinispanPath);
			return this;
		}
		
		public ManagedInfinispanRuleBuilder protocol(String protocol) {
			this.managedInfinispanLifecycleManager.setProtocol(protocol);
			return this;
		}
		
		public ManagedInfinispanRuleBuilder appendCommandLineArguments(String argumentName, String argumentValue) {
			this.managedInfinispanLifecycleManager.addExtraCommandLineArgument(argumentName, argumentValue);
			return this;
		}

		public ManagedInfinispanRuleBuilder appendSingleCommandLineArguments(String argument) {
			this.managedInfinispanLifecycleManager.addSingleCommandLineArgument(argument);
			return this;
		}
		
		public ManagedInfinispan build() {
			
			if(this.managedInfinispanLifecycleManager.getProtocol() == null) {
				throw new IllegalArgumentException("At least not null protocol should be provided [memcached|hotrod|websocket].");
			}

			ManagedInfinispan managedInfinispan = new ManagedInfinispan();
			managedInfinispan.managedInfinispanLifecycleManager = this.managedInfinispanLifecycleManager;
			
			
			return managedInfinispan;
			
		}
		
	}
	
	@Override
	protected void before() throws Throwable {
		this.managedInfinispanLifecycleManager.startEngine();
	}

	@Override
	protected void after() {
		this.managedInfinispanLifecycleManager.stopEngine();
	}

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy