Skip to content

Commit

Permalink
Added unit test for BDD
Browse files Browse the repository at this point in the history
  • Loading branch information
hdreihah committed May 8, 2024
1 parent 64a705a commit be63558
Show file tree
Hide file tree
Showing 5 changed files with 738 additions and 0 deletions.
70 changes: 70 additions & 0 deletions src/test/java/esa/egos/csts/test/bdd/BddProviderSi.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
package esa.egos.csts.test.bdd;

import esa.egos.csts.api.enumerations.CstsResult;
import esa.egos.csts.api.exceptions.ApiException;
import esa.egos.csts.api.main.ICstsApi;
import esa.egos.csts.api.operations.IAcknowledgedOperation;
import esa.egos.csts.api.operations.IConfirmedOperation;
import esa.egos.csts.api.operations.IOperation;
import esa.egos.csts.api.states.service.ServiceStatus;
import esa.egos.csts.app.si.SiConfig;

public class BddProviderSi extends BddSi {

public BddProviderSi(ICstsApi api, SiConfig config, boolean provider, int serviceVersion)
throws ApiException {
super(api, config, provider, serviceVersion);
}

/**
* Transfers the
* @param data
* @return
*/
public CstsResult sendData(byte[] data) {
if(getApiServiceInstance().getStatus() == ServiceStatus.UNBOUND) {
return CstsResult.FAILURE;
}

CstsResult res = bddProcedure.transferData(data);

return res;
}

@Override
public void informOpInvocation(IOperation operation) {
System.out.println("BDD provider inform operation invoke: " + operation);

}

@Override
public void informOpAcknowledgement(IAcknowledgedOperation operation) {
System.out.println("BDD provider inform operation acknowledgement: " + operation);

}

@Override
public void informOpReturn(IConfirmedOperation operation) {
System.out.println("BDD provider inform operation return: " + operation);

}

@Override
public void protocolAbort() {
System.out.println("BDD provider protocol abort");

}

@Override
protected void initBddProcedure(int instanceNumber) {

bddProcedure.getReturnBufferSize().setValue(1000);
bddProcedure.getReturnBufferSize().setConfigured(true);

bddProcedure.getDeliveryLatencyLimit().setValue(1);
bddProcedure.getDeliveryLatencyLimit().setConfigured(true);

bddProcedure.getDeliveryModeParameter().setValue(2 /* 2 = DeliveryMode.COMPLETE */);
}

}
75 changes: 75 additions & 0 deletions src/test/java/esa/egos/csts/test/bdd/BddSi.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
package esa.egos.csts.test.bdd;

import esa.egos.csts.api.enumerations.ProcedureRole;
import esa.egos.csts.api.exceptions.ApiException;
import esa.egos.csts.api.main.ICstsApi;
import esa.egos.csts.api.oids.ObjectIdentifier;
import esa.egos.csts.api.procedures.buffereddatadelivery.BufferedDataDeliveryProvider;
import esa.egos.csts.api.procedures.buffereddatadelivery.BufferedDataDeliveryUser;
import esa.egos.csts.api.procedures.buffereddatadelivery.IBufferedDataDelivery;
import esa.egos.csts.api.serviceinstance.IServiceInform;
import esa.egos.csts.api.serviceinstance.IServiceInstance;
import esa.egos.csts.api.serviceinstance.IServiceInstanceIdentifier;
import esa.egos.csts.api.serviceinstance.impl.ServiceInstanceIdentifier;
import esa.egos.csts.app.si.SiConfig;

/**
* Base class of a BDD test service SI.
* Holds the CSTS API and the BDD procedure references
*
*/
public abstract class BddSi implements IServiceInform {
private final ICstsApi api;

private IServiceInstance apiServiceInstance;

protected IBufferedDataDelivery bddProcedure;

final ObjectIdentifier bddTestServiceOid = ObjectIdentifier.of(1,3,112,4,4,1,2,1000); /* TODO: adjust */

public BddSi(ICstsApi api, SiConfig config, boolean provider, int serviceVersion) throws ApiException {
this.api = api;


IServiceInstanceIdentifier identifier = new ServiceInstanceIdentifier(config.getScId(),
config.getFacilityId(),
bddTestServiceOid,
config.getInstanceNumber());

apiServiceInstance = api.createServiceInstance(identifier, serviceVersion, this);

if(provider == true) {
bddProcedure = apiServiceInstance.createProcedure(BufferedDataDeliveryProvider.class);
} else {
bddProcedure = apiServiceInstance.createProcedure(BufferedDataDeliveryUser.class);
}

bddProcedure.setRole(ProcedureRole.PRIME, 0);
apiServiceInstance.addProcedure(bddProcedure);

initBddProcedure(1); // instance number 1

// the application needs to make sure that it chooses valid values from the proxy configuration
apiServiceInstance.setPeerIdentifier(config.getPeerIdentifier());
apiServiceInstance.setResponderPortIdentifier(config.getResponderPortIdentifier());
apiServiceInstance.configure();
}

protected abstract void initBddProcedure(int instanceNumber);

/**
* Destroys this SI in API
* @throws ApiException
*/
public void destroy() throws ApiException {
this.api.destroyServiceInstance(apiServiceInstance);
}

/**
* Provides access to the API SI instance
* @return the API SI instance
*/
public IServiceInstance getApiServiceInstance() {
return this.apiServiceInstance;
}
}
Loading

0 comments on commit be63558

Please sign in to comment.