Search in sources :

Example 11 with SearchResultsType

use of net.opengis.cat.csw.v_2_0_2.SearchResultsType in project ddf by codice.

the class TestCswSourceBase method configureMockCsw.

protected void configureMockCsw(int numRecordsReturned, long numRecordsMatched, String cswVersion) throws CswException {
    ServiceIdentification mockServiceIdentification = mock(ServiceIdentification.class);
    when(mockServiceIdentification.getAbstract()).thenReturn("myDescription");
    CapabilitiesType mockCapabilities = mock(CapabilitiesType.class);
    when(mockCapabilities.getVersion()).thenReturn(cswVersion);
    when(mockCapabilities.getServiceIdentification()).thenReturn(mockServiceIdentification);
    when(mockCapabilities.getServiceIdentification()).thenReturn(mockServiceIdentification);
    when(mockCsw.getCapabilities(any(GetCapabilitiesRequest.class))).thenReturn(mockCapabilities);
    FilterCapabilities mockFilterCapabilities = mock(FilterCapabilities.class);
    when(mockCapabilities.getFilterCapabilities()).thenReturn(mockFilterCapabilities);
    List<ComparisonOperatorType> comparisonOpsList = new ArrayList<>();
    comparisonOpsList.add(ComparisonOperatorType.EQUAL_TO);
    comparisonOpsList.add(ComparisonOperatorType.LIKE);
    comparisonOpsList.add(ComparisonOperatorType.NOT_EQUAL_TO);
    comparisonOpsList.add(ComparisonOperatorType.GREATER_THAN);
    comparisonOpsList.add(ComparisonOperatorType.GREATER_THAN_EQUAL_TO);
    comparisonOpsList.add(ComparisonOperatorType.LESS_THAN);
    comparisonOpsList.add(ComparisonOperatorType.LESS_THAN_EQUAL_TO);
    comparisonOpsList.add(ComparisonOperatorType.BETWEEN);
    comparisonOpsList.add(ComparisonOperatorType.NULL_CHECK);
    ComparisonOperatorsType comparisonOps = new ComparisonOperatorsType();
    comparisonOps.setComparisonOperator(comparisonOpsList);
    ScalarCapabilitiesType mockScalarCapabilities = mock(ScalarCapabilitiesType.class);
    when(mockScalarCapabilities.getLogicalOperators()).thenReturn(mock(LogicalOperators.class));
    mockScalarCapabilities.setComparisonOperators(comparisonOps);
    when(mockScalarCapabilities.getComparisonOperators()).thenReturn(comparisonOps);
    when(mockFilterCapabilities.getScalarCapabilities()).thenReturn(mockScalarCapabilities);
    List<DomainType> getRecordsParameters = new ArrayList<>();
    DomainType typeName = new DomainType();
    typeName.setName(CswConstants.TYPE_NAME_PARAMETER);
    typeName.setValue(Collections.singletonList("csw:Record"));
    getRecordsParameters.add(typeName);
    DomainType typeNames = new DomainType();
    typeNames.setName(CswConstants.TYPE_NAMES_PARAMETER);
    getRecordsParameters.add(typeNames);
    DomainType getRecordsOutputSchema = new DomainType();
    getRecordsOutputSchema.setName(CswConstants.OUTPUT_SCHEMA_PARAMETER);
    getRecordsOutputSchema.getValue().add(CswConstants.CSW_OUTPUT_SCHEMA);
    getRecordsParameters.add(getRecordsOutputSchema);
    DomainType constraintLang = new DomainType();
    constraintLang.setName(CswConstants.CONSTRAINT_LANGUAGE_PARAMETER);
    constraintLang.setValue(Collections.singletonList(CswConstants.CONSTRAINT_LANGUAGE_FILTER));
    getRecordsParameters.add(constraintLang);
    DomainType outputFormat = new DomainType();
    outputFormat.setName(CswConstants.OUTPUT_FORMAT_PARAMETER);
    getRecordsParameters.add(outputFormat);
    DomainType resultType = new DomainType();
    resultType.setName(CswConstants.RESULT_TYPE_PARAMETER);
    getRecordsParameters.add(resultType);
    DomainType elementSetName = new DomainType();
    elementSetName.setName(CswConstants.ELEMENT_SET_NAME_PARAMETER);
    getRecordsParameters.add(elementSetName);
    List<DomainType> getRecordByIdParameters = new ArrayList<>();
    DomainType getRecordByIdOutputSchema = new DomainType();
    getRecordByIdOutputSchema.setName(CswConstants.OUTPUT_SCHEMA_PARAMETER);
    List<String> outputSchemas = new ArrayList<>();
    outputSchemas.add(CswConstants.CSW_OUTPUT_SCHEMA);
    getRecordByIdOutputSchema.setValue(outputSchemas);
    getRecordByIdParameters.add(getRecordByIdOutputSchema);
    Operation getRecords = new Operation();
    getRecords.setName(CswConstants.GET_RECORDS);
    getRecords.setParameter(getRecordsParameters);
    Operation getRecordById = new Operation();
    getRecordById.setName(CswConstants.GET_RECORD_BY_ID);
    getRecordById.setParameter(getRecordByIdParameters);
    List<Operation> operations = new ArrayList<>(2);
    operations.add(getRecords);
    operations.add(getRecordById);
    OperationsMetadata mockOperationsMetadata = mock(OperationsMetadata.class);
    mockOperationsMetadata.setOperation(operations);
    when(mockCapabilities.getOperationsMetadata()).thenReturn(mockOperationsMetadata);
    when(mockOperationsMetadata.getOperation()).thenReturn(operations);
    if (numRecordsReturned > 0) {
        List<Metacard> metacards = new ArrayList<>(numRecordsReturned);
        for (int i = 1; i <= numRecordsReturned; i++) {
            String id = "ID_" + String.valueOf(i);
            MetacardImpl metacard = new MetacardImpl();
            metacard.setId(id);
            metacard.setContentTypeName("myContentType");
            metacards.add(metacard);
        }
        SearchResultsType searchResults = mock(SearchResultsType.class);
        when(searchResults.getNumberOfRecordsMatched()).thenReturn(BigInteger.valueOf(numRecordsMatched));
        when(searchResults.getNumberOfRecordsReturned()).thenReturn(BigInteger.valueOf(numRecordsReturned));
        CswRecordCollection mockCswRecordCollection = mock(CswRecordCollection.class);
        when(mockCswRecordCollection.getCswRecords()).thenReturn(metacards);
        when(mockCswRecordCollection.getNumberOfRecordsMatched()).thenReturn(numRecordsMatched);
        when(mockCswRecordCollection.getNumberOfRecordsReturned()).thenReturn((long) numRecordsReturned);
        when(mockCsw.getRecords(any(GetRecordsType.class))).thenReturn(mockCswRecordCollection);
    }
}
Also used : GetCapabilitiesRequest(org.codice.ddf.spatial.ogc.csw.catalog.common.GetCapabilitiesRequest) OperationsMetadata(net.opengis.ows.v_1_0_0.OperationsMetadata) SearchResultsType(net.opengis.cat.csw.v_2_0_2.SearchResultsType) ArrayList(java.util.ArrayList) LogicalOperators(net.opengis.filter.v_1_1_0.LogicalOperators) GetRecordsType(net.opengis.cat.csw.v_2_0_2.GetRecordsType) Matchers.anyString(org.mockito.Matchers.anyString) Operation(net.opengis.ows.v_1_0_0.Operation) MetacardImpl(ddf.catalog.data.impl.MetacardImpl) FilterCapabilities(net.opengis.filter.v_1_1_0.FilterCapabilities) ComparisonOperatorsType(net.opengis.filter.v_1_1_0.ComparisonOperatorsType) Metacard(ddf.catalog.data.Metacard) DomainType(net.opengis.ows.v_1_0_0.DomainType) ScalarCapabilitiesType(net.opengis.filter.v_1_1_0.ScalarCapabilitiesType) ScalarCapabilitiesType(net.opengis.filter.v_1_1_0.ScalarCapabilitiesType) CapabilitiesType(net.opengis.cat.csw.v_2_0_2.CapabilitiesType) CswRecordCollection(org.codice.ddf.spatial.ogc.csw.catalog.common.CswRecordCollection) ComparisonOperatorType(net.opengis.filter.v_1_1_0.ComparisonOperatorType) ServiceIdentification(net.opengis.ows.v_1_0_0.ServiceIdentification)

Aggregations

SearchResultsType (net.opengis.cat.csw.v_2_0_2.SearchResultsType)11 GetRecordsResponseType (net.opengis.cat.csw.v_2_0_2.GetRecordsResponseType)10 GetRecordsType (net.opengis.cat.csw.v_2_0_2.GetRecordsType)7 CswRecordCollection (org.codice.ddf.spatial.ogc.csw.catalog.common.CswRecordCollection)7 Matchers.anyString (org.mockito.Matchers.anyString)7 XStream (com.thoughtworks.xstream.XStream)6 ByteArrayInputStream (java.io.ByteArrayInputStream)6 JAXBElement (javax.xml.bind.JAXBElement)6 Ignore (jdk.nashorn.internal.ir.annotations.Ignore)6 ObjectFactory (net.opengis.cat.csw.v_2_0_2.ObjectFactory)6 QueryType (net.opengis.cat.csw.v_2_0_2.QueryType)6 MarshallingContext (com.thoughtworks.xstream.converters.MarshallingContext)5 HierarchicalStreamWriter (com.thoughtworks.xstream.io.HierarchicalStreamWriter)5 ElementSetNameType (net.opengis.cat.csw.v_2_0_2.ElementSetNameType)5 ArrayList (java.util.ArrayList)3 Test (org.junit.Test)3 Metacard (ddf.catalog.data.Metacard)2 NoNameCoder (com.thoughtworks.xstream.io.naming.NoNameCoder)1 StaxDriver (com.thoughtworks.xstream.io.xml.StaxDriver)1 MetacardImpl (ddf.catalog.data.impl.MetacardImpl)1