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

com.ecfeed.junit.runner.local.ServiceLocalTestSuiteRunnable 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.runner.local;

import java.lang.reflect.Method;
import java.util.List;
import java.util.Optional;
import java.util.concurrent.BlockingQueue;

import com.ecfeed.core.generators.api.GeneratorException;
import com.ecfeed.core.model.ChoiceNode;
import com.ecfeed.core.model.MethodNode;
import com.ecfeed.core.utils.TestCasesUserInput;
import com.ecfeed.junit.message.MessageHelper;
import com.ecfeed.junit.runner.UserInputHelper;
import com.ecfeed.junit.utils.Localization;
import com.ecfeed.junit.utils.Logger;

public class ServiceLocalTestSuiteRunnable implements Runnable {
	
	private volatile BlockingQueue fResponseQueue;
	
	private List> testCases;

	public ServiceLocalTestSuiteRunnable(BlockingQueue responseQueue, Method testMethod, TestCasesUserInput request, String model) {
		fResponseQueue = responseQueue;
		
		try {
			MethodNode methodNode = UserInputHelper.getMethodNodeFromEcFeedModel(testMethod, model, Optional.ofNullable(request.getMethod()));
			testCases = UserInputHelper.getTestsFromEcFeedModel(methodNode, Optional.ofNullable(request.getTestSuites()));
		} catch (GeneratorException e) {
			RuntimeException exception = new RuntimeException(Localization.bundle.getString("generatorInitializationError"), e);
			exception.addSuppressed(e);
			Logger.exception(exception);
			throw exception;
		}
	}
	
	@Override
	public void run() {
		Logger.message("");

		int iteration = 0;
		
		fResponseQueue.offer(MessageHelper.resultStartDataSchema("LOCAL", false));
		fResponseQueue.offer(MessageHelper.resultStartChunkSchema("LOCAL"));
		
		for (List tuple : testCases) {
			
			if (iteration % 10 == 0) {
				fResponseQueue.offer(MessageHelper.resultProgressSchema(iteration));
			}
			
			fResponseQueue.offer(MessageHelper.resultTestSchema(tuple, "" + iteration));
			
			iteration++;	
		}
		
		fResponseQueue.offer(MessageHelper.resultEndChunkSchema());
		fResponseQueue.offer(MessageHelper.resultEndDataSchema("LOCAL"));
		fResponseQueue.offer("");		
	}
	
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy