use of net.opengis.cat.csw._3.CapabilitiesType in project ddf by codice.
the class TestCswSourceBase method createMockCsw.
protected Csw createMockCsw() throws CswException {
Csw mockCsw = mock(Csw.class);
InputStream stream = getClass().getResourceAsStream("/getCapabilities.xml");
CapabilitiesType capabilities = parseXml(stream);
when(mockCsw.getCapabilities(any(GetCapabilitiesRequest.class))).thenReturn(capabilities);
CswRecordCollection collection = generateCswCollection("/getBriefRecordsResponse.xml");
when(mockCsw.getRecords(any(GetRecordsType.class))).thenReturn(collection);
return mockCsw;
}
use of net.opengis.cat.csw._3.CapabilitiesType 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);
}
}
use of net.opengis.cat.csw._3.CapabilitiesType in project midpoint by Evolveum.
the class AbstractManualResourceTest method test003Connection.
@Test
public void test003Connection() throws Exception {
final String TEST_NAME = "test003Connection";
TestUtil.displayTestTile(TEST_NAME);
// GIVEN
Task task = createTask(TEST_NAME);
OperationResult result = task.getResult();
// Check that there is a schema, but no capabilities before test (pre-condition)
ResourceType resourceBefore = repositoryService.getObject(ResourceType.class, getResourceOid(), null, result).asObjectable();
Element resourceXsdSchemaElementBefore = ResourceTypeUtil.getResourceXsdSchema(resourceBefore);
assertResourceSchemaBeforeTest(resourceXsdSchemaElementBefore);
CapabilitiesType capabilities = resourceBefore.getCapabilities();
if (capabilities != null) {
AssertJUnit.assertNull("Native capabilities present before test connection. Bad test setup?", capabilities.getNative());
}
// WHEN
OperationResult testResult = modelService.testResource(getResourceOid(), task);
// THEN
display("Test result", testResult);
TestUtil.assertSuccess("Test resource failed (result)", testResult);
PrismObject<ResourceType> resourceRepoAfter = repositoryService.getObject(ResourceType.class, getResourceOid(), null, result);
ResourceType resourceTypeRepoAfter = resourceRepoAfter.asObjectable();
display("Resource after test", resourceTypeRepoAfter);
XmlSchemaType xmlSchemaTypeAfter = resourceTypeRepoAfter.getSchema();
assertNotNull("No schema after test connection", xmlSchemaTypeAfter);
Element resourceXsdSchemaElementAfter = ResourceTypeUtil.getResourceXsdSchema(resourceTypeRepoAfter);
assertNotNull("No schema after test connection", resourceXsdSchemaElementAfter);
String resourceXml = prismContext.serializeObjectToString(resourceRepoAfter, PrismContext.LANG_XML);
display("Resource XML", resourceXml);
CachingMetadataType cachingMetadata = xmlSchemaTypeAfter.getCachingMetadata();
assertNotNull("No caching metadata", cachingMetadata);
assertNotNull("No retrievalTimestamp", cachingMetadata.getRetrievalTimestamp());
assertNotNull("No serialNumber", cachingMetadata.getSerialNumber());
Element xsdElement = ObjectTypeUtil.findXsdElement(xmlSchemaTypeAfter);
ResourceSchema parsedSchema = ResourceSchemaImpl.parse(xsdElement, resourceBefore.toString(), prismContext);
assertNotNull("No schema after parsing", parsedSchema);
// schema will be checked in next test
}
use of net.opengis.cat.csw._3.CapabilitiesType in project midpoint by Evolveum.
the class AbstractBasicDummyTest method test025CapabilitiesRepo.
/**
* Check if the cached native capabilities were properly stored in the repo
*/
@Test
public void test025CapabilitiesRepo() throws Exception {
final String TEST_NAME = "test025CapabilitiesRepo";
TestUtil.displayTestTile(TEST_NAME);
// GIVEN
OperationResult result = new OperationResult(AbstractBasicDummyTest.class.getName() + "." + TEST_NAME);
// WHEN
PrismObject<ResourceType> resource = repositoryService.getObject(ResourceType.class, RESOURCE_DUMMY_OID, null, result);
;
// THEN
result.computeStatus();
display("getObject result", result);
TestUtil.assertSuccess(result);
// Check native capabilities
ResourceType resourceType = resource.asObjectable();
CapabilitiesType capabilitiesType = resourceType.getCapabilities();
assertNotNull("No capabilities in repo, the capabilities were not cached", capabilitiesType);
CapabilityCollectionType nativeCapabilities = capabilitiesType.getNative();
System.out.println("Native capabilities: " + PrismTestUtil.serializeAnyDataWrapped(nativeCapabilities));
System.out.println("resource: " + resourceType.asPrismObject().debugDump());
List<Object> nativeCapabilitiesList = nativeCapabilities.getAny();
assertFalse("Empty capabilities returned", nativeCapabilitiesList.isEmpty());
CredentialsCapabilityType capCred = CapabilityUtil.getCapability(nativeCapabilitiesList, CredentialsCapabilityType.class);
assertNotNull("password native capability not present", capCred.getPassword());
ActivationCapabilityType capAct = CapabilityUtil.getCapability(nativeCapabilitiesList, ActivationCapabilityType.class);
if (supportsActivation()) {
assertNotNull("native activation capability not present", capAct);
assertNotNull("native activation status capability not present", capAct.getStatus());
} else {
assertNull("native activation capability sneaked in", capAct);
}
TestConnectionCapabilityType capTest = CapabilityUtil.getCapability(nativeCapabilitiesList, TestConnectionCapabilityType.class);
assertNotNull("native test capability not present", capTest);
ScriptCapabilityType capScript = CapabilityUtil.getCapability(nativeCapabilitiesList, ScriptCapabilityType.class);
assertNotNull("native script capability not present", capScript);
assertNotNull("No host in native script capability", capScript.getHost());
assertFalse("No host in native script capability", capScript.getHost().isEmpty());
// TODO: better look inside
CachingMetadataType repoCapabilitiesCachingMetadataType = capabilitiesType.getCachingMetadata();
assertNotNull("No repo capabilities caching metadata", repoCapabilitiesCachingMetadataType);
assertNotNull("No repo capabilities caching metadata timestamp", repoCapabilitiesCachingMetadataType.getRetrievalTimestamp());
assertNotNull("No repo capabilities caching metadata serial number", repoCapabilitiesCachingMetadataType.getSerialNumber());
assertEquals("Repo capabilities caching metadata timestamp does not match previously returned value", capabilitiesCachingMetadataType.getRetrievalTimestamp(), repoCapabilitiesCachingMetadataType.getRetrievalTimestamp());
assertEquals("Repo capabilities caching metadata serial does not match previously returned value", capabilitiesCachingMetadataType.getSerialNumber(), repoCapabilitiesCachingMetadataType.getSerialNumber());
assertSteadyResource();
}
use of net.opengis.cat.csw._3.CapabilitiesType in project midpoint by Evolveum.
the class ResourceManager method isComplete.
private boolean isComplete(PrismObject<ResourceType> resource) {
ResourceType resourceType = resource.asObjectable();
Element xsdSchema = ResourceTypeUtil.getResourceXsdSchema(resource);
if (xsdSchema == null) {
return false;
}
CapabilitiesType capabilitiesType = resourceType.getCapabilities();
if (capabilitiesType == null) {
return false;
}
CachingMetadataType capCachingMetadata = capabilitiesType.getCachingMetadata();
if (capCachingMetadata == null) {
return false;
}
return true;
}
Aggregations