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

com.ecfeed.junit.EcFeedArgumentsProviderIterator Maven / Gradle / Ivy

Go to download

An open library used to connect to the ecFeed service. It can be also used as a standalone testing tool. It is integrated with Junit5 and generates a stream of test cases using a selected algorithm (e.g. Cartesian, N-Wise). There are no limitations associated with the off-line version but the user cannot access the on-line computation servers and the model database.

The newest version!
package com.ecfeed.junit;

import java.lang.reflect.Parameter;
import java.util.Iterator;
import java.util.Optional;
import java.util.concurrent.BlockingQueue;

import org.junit.jupiter.api.extension.ExtensionContext;
import org.junit.jupiter.api.extension.ExtensionContext.Namespace;
import org.junit.jupiter.params.provider.Arguments;

import com.ecfeed.junit.message.ArgumentChainJUnit5;
import com.ecfeed.junit.utils.Localization;
import com.ecfeed.junit.utils.Logger;

public class EcFeedArgumentsProviderIterator implements Iterator  {
	private final BlockingQueue fDataBlockingQueue;
	private final EcFeedExtensionStore fStore;
	private final Parameter[] fParameters;
	
	private Arguments fTestCaseArguments;

	private EcFeedArgumentsProviderIterator(BlockingQueue dataBlockingQueue, ExtensionContext context) {
		fStore = (EcFeedExtensionStore) context.getStore(Namespace.create("ecFeed")).get("ecFeedStore");
		fParameters = context.getTestMethod().get().getParameters();
		fDataBlockingQueue = dataBlockingQueue;
	}
	
	public static EcFeedArgumentsProviderIterator create(BlockingQueue dataBlockingQueue, ExtensionContext context) {
		if (dataBlockingQueue == null) {
			RuntimeException exception = new NullPointerException(Localization.bundle.getString("ecFeedArgumentsProviderIteratorBlockingQueueError"));
			Logger.exception(exception);
			throw exception;
		}
		
		return new EcFeedArgumentsProviderIterator(dataBlockingQueue, context);
	}
	
	@Override
	public boolean hasNext() {
		return (fTestCaseArguments = getTestCase(fDataBlockingQueue)) != null;
	}

	@Override
	public Arguments next() {
		return fTestCaseArguments; 
	}
	
	private Arguments getTestCase(BlockingQueue dataBlockingQueue) {
		String testCaseMessage;
		Optional testCaseArguments;
		
		try {
			
			do {
				testCaseMessage = dataBlockingQueue.take();
				
				if (testCaseMessage.equals("")) {
					return null;
				}
				
				testCaseArguments = ArgumentChainJUnit5.extract(testCaseMessage, fParameters, fStore);
			} while (!testCaseArguments.isPresent());
			
			
		} catch (InterruptedException e) {
			RuntimeException exception = new RuntimeException(Localization.bundle.getString("ecFeedArgumentsProviderIteratorBlockingQueueCorruptedError"));
			Logger.exception(exception);
			throw exception;
		}
		
		return testCaseArguments.get();
	}
	
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy