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

org.opengis.cite.ogcapifeatures10.conformance.CommonDataFixture Maven / Gradle / Ivy

There is a newer version: 1.7.1
Show newest version
package org.opengis.cite.ogcapifeatures10.conformance;

import static org.opengis.cite.ogcapifeatures10.conformance.SuiteAttribute.API_MODEL;
import static org.opengis.cite.ogcapifeatures10.conformance.SuiteAttribute.NO_OF_COLLECTIONS;
import static org.opengis.cite.ogcapifeatures10.conformance.SuiteAttribute.REQUIREMENTCLASSES;

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

import com.reprezen.kaizen.oasparser.model3.OpenApi3;
import org.testng.ITestContext;
import org.testng.SkipException;
import org.testng.annotations.BeforeClass;

/**
 * @author Lyn Goltz 
 */
public class CommonDataFixture extends CommonFixture {

    private static final int DEFAULT_NUMBER_OF_COLLECTIONS = 3;

    private OpenApi3 apiModel;

    private List requirementClasses;

    protected int noOfCollections = DEFAULT_NUMBER_OF_COLLECTIONS;

    @BeforeClass
    public void requirementClasses( ITestContext testContext ) {
        this.requirementClasses = (List) testContext.getSuite().getAttribute( REQUIREMENTCLASSES.getName() );
    }

    @BeforeClass
    public void noOfCollections( ITestContext testContext ) {
        Object noOfCollections = testContext.getSuite().getAttribute( NO_OF_COLLECTIONS.getName() );
        if ( noOfCollections != null ) {
            this.noOfCollections = (Integer) noOfCollections;
        }
    }

    @BeforeClass
    public void retrieveApiModel( ITestContext testContext ) {
        this.apiModel = (OpenApi3) testContext.getSuite().getAttribute( API_MODEL.getName() );
    }

    public OpenApi3 getApiModel() {
        if ( apiModel == null )
            throw new SkipException( "ApiModel is not available." );
        return apiModel;
    }

    protected List createListOfMediaTypesToSupportForOtherResources( Map linkToSelf ) {
        if ( this.requirementClasses == null )
            throw new SkipException( "No requirement classes described in  resource /conformance available" );
        List mediaTypesToSupport = new ArrayList<>();
        for ( RequirementClass requirementClass : this.requirementClasses )
            if ( requirementClass.hasMediaTypeForOtherResources() )
                mediaTypesToSupport.add( requirementClass.getMediaTypeOtherResources() );
        if ( linkToSelf != null )
            mediaTypesToSupport.remove( linkToSelf.get( "type" ) );
        return mediaTypesToSupport;
    }

    protected List createListOfMediaTypesToSupportForFeatureCollectionsAndFeatures() {
        if ( this.requirementClasses == null )
            throw new SkipException( "No requirement classes described in  resource /conformance available" );
        List mediaTypesToSupport = new ArrayList<>();
        for ( RequirementClass requirementClass : this.requirementClasses )
            if ( requirementClass.hasMediaTypeForFeaturesAndCollections() )
                mediaTypesToSupport.add( requirementClass.getMediaTypeFeaturesAndCollections() );
        return mediaTypesToSupport;
    }

    protected List createListOfMediaTypesToSupportForFeatureCollectionsAndFeatures( Map linkToSelf ) {
        List mediaTypesToSupport = createListOfMediaTypesToSupportForFeatureCollectionsAndFeatures();
        if ( linkToSelf != null )
            mediaTypesToSupport.remove( linkToSelf.get( "type" ) );
        return mediaTypesToSupport;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy