Commit f54d5b9f authored by Martti Käärik's avatar Martti Käärik
Browse files

Extended TRI implementation and code generation support.

parent 57dc92e6
Loading
Loading
Loading
Loading
Loading
+90 −0
Original line number Diff line number Diff line
package org.etsi.mts.tdl.execution.java.rt.core;

import java.util.Hashtable;
import java.util.Map;

import org.etsi.mts.tdl.execution.java.tri.ElementAnnotation;
import org.etsi.mts.tdl.execution.java.tri.Mapping;

public class MappingImpl extends Mapping implements TriImpl<MappingImpl, MappingImpl> {
	private String mappingName;

	private boolean resource;
	private boolean parameter;
	private String uri;

	private MappingImpl container;
	private Map<String, MappingImpl> parameters = new Hashtable<String, MappingImpl>();

	public MappingImpl() {
	}

	public MappingImpl(String mappingName, String uri) {
		this.mappingName = mappingName;
		this.uri = uri;
	}

	@Override
	public String getUri() {
		return uri;
	}

	@Override
	public String getMappingName() {
		return mappingName;
	}

	public MappingImpl setIsResource(boolean resource) {
		this.resource = resource;
		return this;
	}

	public MappingImpl setIsParameter(boolean parameter) {
		this.parameter = parameter;
		return this;
	}

	@Override
	public boolean isResource() {
		return resource;
	}

	@Override
	public boolean isParameter() {
		return parameter;
	}

	public MappingImpl setResource(MappingImpl container) {
		this.container = container;
		return this;
	}

	@Override
	public MappingImpl getResource() {
		return container;
	}

	@Override
	public MappingImpl setParameter(String name, MappingImpl mapping) {
		this.parameters.put(name, mapping);
		return this;
	}

	@Override
	public MappingImpl getParameter(String name) {
		return this.parameters.get(name);
	}

	@Override
	public MappingImpl setName(String name, String qualifiedName) {
		this.name = name;
		return this;
	}
	
	@Override
	public MappingImpl addAnnotation(String key, String value) {
		this.annotations.add(new ElementAnnotation(key, value));
		return this;
	}

}
+26 −7
Original line number Diff line number Diff line
@@ -37,7 +37,8 @@ public class TestControl {
	public RuntimeHelper runtimeHelper;

	private Connection[] connections;
	private Map<Connection, ReceiverHub> receiverHubs = Collections.synchronizedMap(new Hashtable<Connection, ReceiverHub>());
	private Map<Connection, ReceiverHub> receiverHubs = Collections
			.synchronizedMap(new Hashtable<Connection, ReceiverHub>());

	protected ExecutorCompletionService<ExecutionResult> completionService;
	protected ExecutorService executor;
@@ -47,6 +48,8 @@ public class TestControl {
	private List<ExceptionalBehaviour> exceptionalBehaviours = Collections
			.synchronizedList(new ArrayList<ExceptionalBehaviour>());

	protected Map<String, TypeImpl> types = new Hashtable<String, TypeImpl>();

	public TestControl(com.google.inject.Module guiceModule) {
		super();

@@ -97,6 +100,8 @@ public class TestControl {
			};
			hub.setAnyReceiver(anyReceiver);
		}

		declareTypes();
	}

	public Connection getConnection(String testerComponentName, String testerGateName, String remoteComponentName,
@@ -234,7 +239,6 @@ public class TestControl {
		return receive(expected, connection, true);
	}


	public ExecutionCallable receive(Data expected, Connection connection, boolean isTrigger) {
		ExecutionCallableWithDefaults c = new ExecutionCallableWithDefaults() {
			@Override
@@ -367,4 +371,19 @@ public class TestControl {
			f2.cancel(true);
		}
	}

	/**
	 * This is called once before each test case. Implemented by generated code to
	 * declare types and mappings if using unmapped data in TRI.
	 */
	protected void declareTypes() {
	}

	protected void addType(String name, TypeImpl type) {
		this.types.put(name, type);
	}

	protected TypeImpl getType(String name) {
		return this.types.get(name);
	}
}
+7 −0
Original line number Diff line number Diff line
package org.etsi.mts.tdl.execution.java.rt.core;

public interface TriImpl<I, P> {
	I setName(String name, String qualifiedName);
	I addAnnotation(String key, String value);
	I setParameter(String name, P mapping);
}
+115 −0
Original line number Diff line number Diff line
package org.etsi.mts.tdl.execution.java.rt.core;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Hashtable;
import java.util.List;
import java.util.Map;

import org.etsi.mts.tdl.execution.java.tri.Data;
import org.etsi.mts.tdl.execution.java.tri.ElementAnnotation;
import org.etsi.mts.tdl.execution.java.tri.Mapping;
import org.etsi.mts.tdl.execution.java.tri.Type;
import org.etsi.mts.tdl.execution.java.tri.Value;

public class TypeImpl extends Type implements TriImpl<TypeImpl, TypeImpl> {
	private boolean structure = false;
	private boolean collection = false;
	private boolean enumerated = false;

	private Map<String, TypeImpl> parameters = new Hashtable<String, TypeImpl>();
	private TypeImpl itemType = null;
	private List<Data<Type, Value>> enumLiterals = new ArrayList<Data<Type,Value>>();

	private MappingImpl mapping;

	public TypeImpl setIsStructure(boolean structure) {
		this.structure = structure;
		return this;
	}

	public TypeImpl setIsCollection(boolean collection) {
		this.collection = collection;
		return this;
	}
	
	public TypeImpl setIsEnum(boolean enumerated) {
		this.enumerated = enumerated;
		return this;
	}

	@Override
	public boolean isStructure() {
		return this.structure;
	}

	@Override
	public boolean isCollection() {
		return this.collection;
	}
	
	@Override
	public boolean isEnum() {
		return this.enumerated;
	}

	public TypeImpl setMapping(Mapping mapping) {
		this.mapping = (MappingImpl) mapping;
		return this;
	}

	@Override
	public MappingImpl getMapping() {
		return mapping;
	}

	@Override
	public TypeImpl setParameter(String name, TypeImpl type) {
		this.parameters.put(name, type);
		return this;
	}

	@Override
	public TypeImpl getParameter(String name) {
		return this.parameters.get(name);
	}

	@Override
	public Collection<String> getParameters() {
		return this.parameters.keySet();
	}

	public TypeImpl setItemType(TypeImpl itemType) {
		this.itemType = itemType;
		return this;
	}

	@Override
	public TypeImpl getItemType() {
		return this.itemType;
	}
	
	@Override
	public List<Data<Type, Value>> getEnumLiterals() {
		return this.enumLiterals;
	}
	
	public TypeImpl addEnumLiteral(ValueImpl literal) {
		this.enumLiterals.add(new Data<Type, Value>(this, literal));
		return this;
	}

	@Override
	public TypeImpl setName(String name, String qualifiedName) {
		this.name = name;
		this.qualifiedName = qualifiedName;
		return this;
	}

	@Override
	public TypeImpl addAnnotation(String key, String value) {
		this.annotations.add(new ElementAnnotation(key, value));
		return this;	
	}

}
+127 −0
Original line number Diff line number Diff line
package org.etsi.mts.tdl.execution.java.rt.core;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Hashtable;
import java.util.List;
import java.util.Map;

import org.etsi.mts.tdl.execution.java.tri.Data;
import org.etsi.mts.tdl.execution.java.tri.ElementAnnotation;
import org.etsi.mts.tdl.execution.java.tri.Mapping;
import org.etsi.mts.tdl.execution.java.tri.Type;
import org.etsi.mts.tdl.execution.java.tri.Value;

public class ValueImpl extends Value implements TriImpl<ValueImpl, Data<Type, Value>> {
	private TypeImpl type;

	private boolean collection = false;
	private boolean structure = false;

	private Object value = null;
	private Map<String, Data<Type, Value>> parameters = new Hashtable<String, Data<Type, Value>>();
	private List<Data<Type, Value>> items = new ArrayList<Data<Type, Value>>();

	private MappingImpl mapping;
	
	public ValueImpl() {
	}

	public ValueImpl(TypeImpl type) {
		this.type = type;
	}
	
	public ValueImpl setType(TypeImpl type) {
		this.type = type;
		return this;
	}

	public ValueImpl setIsCollection(boolean collection) {
		this.collection = collection;
		return this;
	}

	public ValueImpl setIsStructure(boolean structure) {
		this.structure = structure;
		return this;
	}

	@Override
	public boolean isCollection() {
		return this.collection;
	}

	@Override
	public boolean isStructure() {
		return this.structure;
	}

	public ValueImpl setMapping(Mapping mapping) {
		this.mapping = (MappingImpl) mapping;
		return this;
	}

	@Override
	public MappingImpl getMapping() {
		return mapping;
	}

	@Override
	public Object getValue() {
		return this.value;
	}

	public ValueImpl setValue(Object value) {
		this.value = value;
		return this;
	}
	
	@Override
	public Collection<String> getParameters() {
		return this.parameters.keySet();
	}

	@Override
	public Data<Type, Value> getParameter(String name) {
		return this.parameters.get(name);
	}

	@Override
	public ValueImpl setParameter(String name, Data<Type, Value> value) {
		this.parameters.put(name, value);
		return this;
	}

	@Override
	public List<Data<Type, Value>> getItems() {
		return this.items;
	}

	public ValueImpl addItem(Data<Type, Value> item) {
		this.items.add(item);
		return this;
	}

	public ValueImpl setItems(List<Data<Type, Value>> items) {
		this.items = items;
		return this;
	}

	@Override
	public ValueImpl setName(String name, String qualifiedName) {
		this.name = name;
		this.qualifiedName = qualifiedName;
		return this;
	}

	@Override
	public ValueImpl addAnnotation(String key, String value) {
		this.annotations.add(new ElementAnnotation(key, value));
		return this;
	}

	public Data<Type, Value> asData() {
		return new Data<Type, Value>(type, this);
	}

}
Loading