Skip to content

Commit

Permalink
Merge pull request #7328 from mandy-chessell/code2023
Browse files Browse the repository at this point in the history
Add new tests to CTS
  • Loading branch information
mandy-chessell authored Jan 29, 2023
2 parents b8c0f65 + 94823cc commit d2c29f5
Show file tree
Hide file tree
Showing 51 changed files with 4,327 additions and 2,392 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public abstract class OpenMetadataConformanceWorkbenchWorkPad
* Add time of last received event - this is to help with determining whether workbench has completed
*/
protected Date lastActive = new Date();
private static final long DELAY_TIME = 10000l; // 10 seconds - time to wait after activity has quiesced before reporting completion
private static final long DELAY_TIME = 10000L; // 10 seconds - time to wait after activity has quiesced before reporting completion

/**
* Constructor takes properties that are common to all work pads.
Expand Down Expand Up @@ -150,7 +150,6 @@ public OpenMetadataConformanceWorkbenchStatus getWorkbenchStatus()
* Set the completion state of the workbench to true.
* This signifies that the synchronous portion of the tests have completed.
* The workbench may still be processing asynchronous events which trigger further tests.
*
*/
public void setWorkbenchComplete()
{
Expand Down Expand Up @@ -356,24 +355,19 @@ protected OpenMetadataConformanceStatus processEvidence(List<OpenMetadataConform
break;

case SUCCESSFUL_ASSERTION:
case DISCOVERED_PROPERTY:
positiveTestEvidence.add(testEvidenceItem);
break;

case UNEXPECTED_EXCEPTION:
case UNSUCCESSFUL_ASSERTION:
negativeTestEvidence.add(testEvidenceItem);
break;

case DISCOVERED_PROPERTY:
positiveTestEvidence.add(testEvidenceItem);
break;

case NOT_SUPPORTED_FUNCTION:
unsupportedTestEvidence.add(testEvidenceItem);
break;

case UNEXPECTED_EXCEPTION:
negativeTestEvidence.add(testEvidenceItem);
break;
}
}
}
Expand Down Expand Up @@ -480,7 +474,7 @@ public synchronized void addUnsuccessfulCondition(Integer profileId,


/**
* Log that a test case has reported the correct response to a non supported function.
* Log that a test case has reported the correct response to a non-supported function.
*
* @param profileId profile for the requirement
* @param requirementId identifier of the requirement
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,10 @@ public abstract class OpenMetadataTestCase
protected String successMessage = null;

/*
* Enumerated type for control of multi-phase tests
* Enumerated type for control of multiphase tests
*/
public enum TestPhase {
public enum TestPhase
{
SEED,
EXECUTE,
CLEAN
Expand All @@ -52,7 +53,7 @@ public OpenMetadataTestCase()


/**
* Typical constructor used when the test case Id is fixed.
* Typical constructor used when the test case id is fixed.
*
* @param workPad location for workbench results
* @param testCaseId identifier of test case
Expand All @@ -78,7 +79,7 @@ public OpenMetadataTestCase(OpenMetadataConformanceWorkbenchWorkPad workPad,


/**
* Typical constructor used when the test case Id needs to be constructed by the test case code.
* Typical constructor used when the test case id needs to be constructed by the test case code.
*
* @param workPad location for workbench results
* @param defaultProfileId identifier of default profile (for unexpected exceptions)
Expand All @@ -95,7 +96,7 @@ public OpenMetadataTestCase(OpenMetadataConformanceWorkbenchWorkPad workPad,


/**
* Update the test case Id, name and documentation URL if not already supplied in the constructor.
* Update the test case id, name and documentation URL if not already supplied in the constructor.
*
* @param testCaseRootId common identifier of test case
* @param testCaseId unique identifier of test case
Expand Down Expand Up @@ -163,7 +164,7 @@ public String getTestCaseDescriptionURL()


/**
* Has the test case been ran yet?
* Has the test case run yet?
*
* @return boolean flag
*/
Expand Down Expand Up @@ -250,6 +251,41 @@ protected void assertCondition(boolean condition,
}


/**
* Throw an exception if the condition is not true; else return
*
* @param object1 object to test
* @param object2 object to test
* @param assertionId identifier for the assertion
* @param assertionMessage descriptive message of the assertion
* @param profileId identifier of profile for this assertion
* @param requirementId identifier of requirement for this assertion
* @param methodName method that this condition tests
* @param elapsedTime of the test executing (in milliseconds)
* @throws AssertionFailureException condition was false
*/
protected void assertObjectsAreEqual(Object object1,
Object object2,
String assertionId,
String assertionMessage,
Integer profileId,
Integer requirementId,
String methodName,
Long elapsedTime) throws AssertionFailureException
{
if (object1.equals(object2))
{
successfulAssertions.add(assertionId + ": " +assertionMessage);
workPad.addSuccessfulCondition(profileId, requirementId, testCaseId, testCaseName, testCaseDescriptionURL, assertionId, methodName, elapsedTime);
return;
}

unsuccessfulAssertions.add(assertionId + ": " + assertionMessage + "==>object1=" + object1 + "; ===>object2=" + object2);
workPad.addUnsuccessfulCondition(profileId, requirementId, testCaseId, testCaseName, testCaseDescriptionURL, assertionId, methodName, elapsedTime);
throw new AssertionFailureException(assertionId, assertionMessage);
}


/**
* Throw an exception if the condition is not true; else return
*
Expand Down Expand Up @@ -302,6 +338,39 @@ protected void verifyCondition(boolean condition,
}


/**
* Log if the condition is not true; else return
*
* @param object1 object to test
* @param object2 object to test
* @param assertionId identifier for the assertion
* @param assertionMessage descriptive message of the assertion
* @param profileId identifier of profile for this assertion
* @param requirementId identifier of requirement for this assertion
* @param methodName method that this condition tests
* @param elapsedTime of the test executing (in milliseconds)
*/
protected void verifyObjectsAreEqual(Object object1,
Object object2,
String assertionId,
String assertionMessage,
Integer profileId,
Integer requirementId,
String methodName,
Long elapsedTime)
{
if (object1.equals(object2))
{
successfulAssertions.add(assertionId + ": " + assertionMessage);
workPad.addSuccessfulCondition(profileId, requirementId, testCaseId, testCaseName, testCaseDescriptionURL, assertionId, methodName, elapsedTime);
return;
}

unsuccessfulAssertions.add(assertionId + ": " + assertionMessage + "==>object1=" + object1 + "; ===>object2=" + object2);
workPad.addUnsuccessfulCondition(profileId, requirementId, testCaseId, testCaseName, testCaseDescriptionURL, assertionId, methodName, elapsedTime);
}


/**
* Log if the condition is not true; else return
*
Expand Down Expand Up @@ -421,6 +490,9 @@ public void executeTest()
}
catch (AssertionFailureException exception)
{
/*
* This exception has already been logged
*/
}
catch (Exception exception)
{
Expand Down Expand Up @@ -461,6 +533,9 @@ public void executeTest(TestPhase phase)
}
catch (AssertionFailureException exception)
{
/*
* This is already handled.
*/
}
catch (Exception exception)
{
Expand All @@ -480,11 +555,14 @@ public void executeTest(TestPhase phase)
}


public void cleanTest() {
try {
public void cleanTest()
{
try
{
this.cleanup();
}
catch (Exception exception) {
catch (Exception exception)
{
/* No action taken - the cleanup should be a belt and braces clearing of instances */
}
}
Expand Down Expand Up @@ -514,7 +592,7 @@ protected void cleanup() throws Exception
protected void run(TestPhase phase) throws Exception
{
/*
* Method is overloaded by any multi-phase test case
* Method is overloaded by any multiphase test case
*/
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,8 @@ protected RepositoryConformanceTestCase(RepositoryConformanceWorkPad workPad,

this.repositoryConformanceWorkPad = workPad;

if (workPad != null)
{
cohortRepositoryConnector = workPad.getTutRepositoryConnector();
maxSearchResults = workPad.getMaxSearchResults();
}
cohortRepositoryConnector = workPad.getTutRepositoryConnector();
maxSearchResults = workPad.getMaxSearchResults();
}

/**
Expand Down Expand Up @@ -226,6 +223,7 @@ protected int getMaxSearchResults() {
return maxSearchResults;
}


/**
* Return the repository connector generated from the cohort registration event.
*
Expand Down Expand Up @@ -481,14 +479,14 @@ protected InstanceProperties getAllPropertiesForInstance(String userId, TypeDef
{
Map<String, InstancePropertyValue> propertyMap = new HashMap<>();


for (TypeDefAttribute typeDefAttribute : allTypeDefAttributes)
{
String attributeName = typeDefAttribute.getAttributeName();
AttributeTypeDef attributeType = typeDefAttribute.getAttributeType();
AttributeTypeDefCategory category = attributeType.getCategory();

if (category == AttributeTypeDefCategory.PRIMITIVE) {
if (category == AttributeTypeDefCategory.PRIMITIVE)
{
PrimitiveDef primitiveDef = (PrimitiveDef) attributeType;
propertyMap.put(attributeName, this.getPrimitivePropertyValue(attributeName, primitiveDef));
}
Expand Down Expand Up @@ -529,7 +527,8 @@ protected InstanceProperties generatePropertiesForInstance(String userId, List<
AttributeTypeDefCategory category = attributeType.getCategory();
boolean attrUnique = typeDefAttribute.isUnique();

if (category == AttributeTypeDefCategory.PRIMITIVE) {
if (category == AttributeTypeDefCategory.PRIMITIVE)
{
PrimitiveDef primitiveDef = (PrimitiveDef) attributeType;
propertyMap.put(attributeName, this.getPrimitivePropertyValue(attributeName, primitiveDef, attrUnique, instanceCount));
}
Expand Down Expand Up @@ -573,8 +572,10 @@ protected InstanceProperties getAllUniquePropertiesForInstance(String userId, T
AttributeTypeDef attributeType = typeDefAttribute.getAttributeType();
AttributeTypeDefCategory category = attributeType.getCategory();

if (typeDefAttribute.isUnique()) {
if (category == AttributeTypeDefCategory.PRIMITIVE) {
if (typeDefAttribute.isUnique())
{
if (category == AttributeTypeDefCategory.PRIMITIVE)
{
PrimitiveDef primitiveDef = (PrimitiveDef) attributeType;
propertyMap.put(attributeName, this.getPrimitivePropertyValue(attributeName, primitiveDef));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import org.odpi.openmetadata.conformance.workbenches.repository.RepositoryConformanceWorkPad;
import org.odpi.openmetadata.repositoryservices.connectors.stores.metadatacollectionstore.OMRSMetadataCollection;
import org.odpi.openmetadata.repositoryservices.connectors.stores.metadatacollectionstore.repositoryconnector.OMRSRepositoryConnector;
import org.odpi.openmetadata.repositoryservices.ffdc.exception.RepositoryErrorException;

public class TestMetadataCollectionId extends RepositoryConformanceTestCase
{
Expand Down Expand Up @@ -77,7 +78,26 @@ protected void run() throws Exception
defaultRequirementId);

OMRSMetadataCollection metadataCollection = super.getMetadataCollection();
String mcMetadataCollectionId = metadataCollection.getMetadataCollectionId(workPad.getLocalServerUserId());
String mcMetadataCollectionId = null;

/*
* This is the first attempt to make a remote call to the technology under test.
*/
int retryCount = 0;
do
{
try
{
mcMetadataCollectionId = metadataCollection.getMetadataCollectionId(workPad.getLocalServerUserId());
}
catch (RepositoryErrorException serverNotRunningException)
{
Thread.sleep(1000);
}

retryCount++;

} while ((retryCount < 20) && (mcMetadataCollectionId == null));

verifyCondition((mcMetadataCollectionId != null),
assertion3,
Expand All @@ -91,7 +111,6 @@ protected void run() throws Exception
defaultProfileId,
defaultRequirementId);


addDiscoveredProperty(metadataCollectionIdPropertyName,
mcMetadataCollectionId,
defaultProfileId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@ public class TestClassificationHasSupportedEntities extends RepositoryConformanc

private static final String successMessage = " has at least one supported entity";

private Map<String, EntityDef> entityDefs;
private ClassificationDef classificationDef;
private final Map<String, EntityDef> entityDefs;
private final ClassificationDef classificationDef;

private List<EntityDef> supportedEntityDefsForClassification = new ArrayList<>();
private final List<EntityDef> supportedEntityDefsForClassification = new ArrayList<>();

/**
* Typical constructor sets up superclass and discovered information needed for tests
Expand Down Expand Up @@ -62,7 +62,6 @@ public TestClassificationHasSupportedEntities(RepositoryConformanceWorkPad workP
*/
protected void run() throws Exception
{

/*
* Verify that the supplied TypeDef is valid and update the testId
*/
Expand Down Expand Up @@ -98,7 +97,6 @@ protected void run() throws Exception
}
else
{

super.addNotSupportedAssertion(assertion2,
testTypeName + assertionMsg2 + classificationDef.getName(),
RepositoryConformanceProfileRequirement.ENTITY_LIFECYCLE.getProfileId(),
Expand All @@ -108,10 +106,9 @@ protected void run() throws Exception
}
}


/*
* Verify that there are entities to connect this classification to.
* It the repository does not support any of the valid entity types for this classification.
* If the repository does not support any of the valid entity types for this classification.
* it should not be supporting this classification.
*/
assertCondition((! supportedEntityDefsForClassification.isEmpty()),
Expand Down
Loading

0 comments on commit d2c29f5

Please sign in to comment.