use of org.codice.ddf.cxf.client.ClientBuilderFactory in project ddf by codice.
the class DownloadsStatusEventListenerTest method testGetDownloadStatus.
@Test
public void testGetDownloadStatus() throws URISyntaxException, DownloadException, InterruptedException, IOException {
File downloadSrcFile = new File(this.getClass().getResource("/125bytes.txt").toURI());
File downloadFile = prepareDownloadFile(downloadSrcFile);
MetacardImpl testMetacard = new MetacardImpl();
testMetacard.setId("easyas123");
testMetacard.setResourceURI(downloadFile.toURI());
testMetacard.setResourceSize("125");
ClientBuilderFactory clientBuilderFactory = new ClientBuilderFactoryImpl();
URLResourceReader testURLResourceReader = new URLResourceReader(clientBuilderFactory);
testURLResourceReader.setRootResourceDirectories(new HashSet<String>(Arrays.asList(localResourcePath.toString())));
List<ResourceReader> testResourceReaderList = Collections.singletonList((ResourceReader) testURLResourceReader);
Map<String, Serializable> tmpMap = Collections.emptyMap();
Map<String, Integer> idToBytes = new HashMap<String, Integer>();
testGetDownloadStatusHelper(null, null, null);
testDownloadManager.download(mock(ResourceRequest.class), testMetacard, new LocalResourceRetriever(testResourceReaderList, testMetacard.getResourceURI(), null, tmpMap));
TimeUnit.SECONDS.sleep(2);
testGetDownloadStatusHelper(idToBytes, DownloadManagerState.DownloadState.COMPLETED.name(), downloadFile.getName());
}
use of org.codice.ddf.cxf.client.ClientBuilderFactory in project ddf by codice.
the class CswSubscriptionEndpointTest method setUp.
@Before
public void setUp() throws Exception {
systemKeystoreFile = temporaryFolder.newFile("serverKeystore.jks");
FileOutputStream systemKeyOutStream = new FileOutputStream(systemKeystoreFile);
InputStream systemKeyStream = CswSubscriptionEndpointTest.class.getResourceAsStream("/serverKeystore.jks");
IOUtils.copy(systemKeyStream, systemKeyOutStream);
systemTruststoreFile = temporaryFolder.newFile("serverTruststore.jks");
FileOutputStream systemTrustOutStream = new FileOutputStream(systemTruststoreFile);
InputStream systemTrustStream = CswSubscriptionEndpointTest.class.getResourceAsStream("/serverTruststore.jks");
IOUtils.copy(systemTrustStream, systemTrustOutStream);
System.setProperty(SecurityConstants.KEYSTORE_TYPE, "jks");
System.setProperty(SecurityConstants.TRUSTSTORE_TYPE, "jks");
System.setProperty("ddf.home", "");
System.setProperty(SecurityConstants.KEYSTORE_PATH, systemKeystoreFile.getAbsolutePath());
System.setProperty(SecurityConstants.TRUSTSTORE_PATH, systemTruststoreFile.getAbsolutePath());
System.setProperty(SecurityConstants.KEYSTORE_PASSWORD, password);
System.setProperty(SecurityConstants.TRUSTSTORE_PASSWORD, password);
eventProcessor = mock(EventProcessor.class);
mockInputManager = mock(TransformerManager.class);
mockContext = mock(BundleContext.class);
mockMimeTypeManager = mock(TransformerManager.class);
mockSchemaManager = mock(TransformerManager.class);
validator = mock(Validator.class);
queryFactory = mock(CswQueryFactory.class);
query = mock(QueryRequest.class);
when(queryFactory.getQuery(any(GetRecordsType.class))).thenReturn(query);
serviceRegistration = mock(ServiceRegistration.class);
subscriptionReference = mock(ServiceReference.class);
bundle = mock(Bundle.class);
osgiFilter = mock(Filter.class);
configAdminRef = mock(ServiceReference.class);
configAdmin = mock(ConfigurationAdmin.class);
config = mock(Configuration.class);
SecureCxfClientFactory mockFactory = mock(SecureCxfClientFactory.class);
clientBuilderFactory = mock(ClientBuilderFactory.class);
ClientBuilder<WebClient> clientBuilder = new ClientBuilderImpl<WebClient>(mock(OAuthSecurity.class), mock(SamlSecurity.class), mock(SecurityLogger.class), mock(SecurityManager.class)) {
@Override
public SecureCxfClientFactory<WebClient> build() {
return mockFactory;
}
};
when(clientBuilderFactory.<WebClient>getClientBuilder()).thenReturn(clientBuilder);
Configuration[] configArry = { config };
defaultRequest = createDefaultGetRecordsRequest();
subscription = new CswSubscription(mockMimeTypeManager, defaultRequest.get202RecordsType(), query, clientBuilderFactory, security);
when(osgiFilter.toString()).thenReturn(FILTER_STR);
doReturn(serviceRegistration).when(mockContext).registerService(eq(Subscription.class.getName()), any(Subscription.class), any(Dictionary.class));
doReturn(configAdminRef).when(mockContext).getServiceReference(eq(ConfigurationAdmin.class.getName()));
when(serviceRegistration.getReference()).thenReturn(subscriptionReference);
doReturn(bundle).when(subscriptionReference).getBundle();
when(subscriptionReference.getBundle()).thenReturn(bundle);
when(bundle.getBundleId()).thenReturn(bundleId);
when(mockContext.createFilter(anyString())).thenReturn(osgiFilter);
when(mockContext.getService(eq(configAdminRef))).thenReturn(configAdmin);
when(mockContext.getService(eq(subscriptionReference))).thenReturn(subscription);
when(configAdmin.listConfigurations(eq(FILTER_STR))).thenReturn(configArry);
when(configAdmin.createFactoryConfiguration(anyString(), isNull())).thenReturn(config);
cswSubscriptionEndpoint = new CswSubscriptionEndpointStub(eventProcessor, mockMimeTypeManager, mockSchemaManager, mockInputManager, validator, queryFactory, mockContext, clientBuilderFactory, security);
}
use of org.codice.ddf.cxf.client.ClientBuilderFactory in project ddf by codice.
the class WfsSourceTest method setUpMocks.
private void setUpMocks(final List<String> supportedGeos, final String srsName, final int results, final int hits) throws WfsException {
SecureCxfClientFactory<ExtendedWfs> mockFactory = mock(SecureCxfClientFactory.class);
when(mockFactory.getClient()).thenReturn(mockWfs);
clientBuilderFactory = mock(ClientBuilderFactory.class);
ClientBuilder<ExtendedWfs> clientBuilder = new ClientBuilderImpl<ExtendedWfs>(mock(OAuthSecurity.class), mock(SamlSecurity.class), mock(SecurityLogger.class), mock(SecurityManager.class)) {
@Override
public SecureCxfClientFactory<ExtendedWfs> build() {
return mockFactory;
}
};
when(clientBuilderFactory.<ExtendedWfs>getClientBuilder()).thenReturn(clientBuilder);
// GetCapabilities Response
when(mockWfs.getCapabilities(any(GetCapabilitiesRequest.class))).thenReturn(mockCapabilities);
mockCapabilities.setFilterCapabilities(new FilterCapabilities());
mockCapabilities.getFilterCapabilities().setSpatialCapabilities(new SpatialCapabilitiesType());
mockCapabilities.getFilterCapabilities().getSpatialCapabilities().setSpatialOperators(new SpatialOperatorsType());
if (CollectionUtils.isNotEmpty(supportedGeos)) {
mockCapabilities.getFilterCapabilities().getSpatialCapabilities().getSpatialOperators().getSpatialOperator().addAll(supportedGeos.stream().map(opName -> {
SpatialOperatorType spatialOperatorType = new SpatialOperatorType();
spatialOperatorType.setName(SpatialOperatorNameType.fromValue(opName));
return spatialOperatorType;
}).collect(Collectors.toList()));
}
mockCapabilities.getFilterCapabilities().getSpatialCapabilities().setGeometryOperands(new GeometryOperandsType());
mockCapabilities.getFilterCapabilities().getSpatialCapabilities().getGeometryOperands().getGeometryOperand().addAll(Arrays.asList(Wfs11Constants.POLYGON, Wfs11Constants.POINT));
sampleFeatures = new ArrayList<>();
mockCapabilities.setFeatureTypeList(new FeatureTypeListType());
for (int ii = 0; ii < results; ii++) {
FeatureTypeType feature = new FeatureTypeType();
QName qName;
if (ii == 0) {
qName = new QName("SampleFeature" + ii);
} else {
qName = new QName("http://example.com", "SampleFeature" + ii, "Prefix" + ii);
}
sampleFeatures.add(qName);
feature.setName(qName);
if (null != srsName) {
feature.setDefaultSRS(srsName);
}
mockCapabilities.getFeatureTypeList().getFeatureType().add(feature);
}
List<Metacard> metacards = new ArrayList<>(results);
for (int i = 0; i < results; i++) {
MetacardImpl mc = new MetacardImpl();
mc.setId("ID_" + (i + 1));
metacards.add(mc);
}
when(mockWfs.getFeature(withResultType(ResultTypeType.HITS))).thenReturn(new WfsFeatureCollectionImpl(hits));
when(mockWfs.getFeature(withResultType(ResultTypeType.RESULTS))).thenReturn(new WfsFeatureCollectionImpl(results, metacards));
final ScheduledFuture<?> mockAvailabilityPollFuture = mock(ScheduledFuture.class);
doReturn(mockAvailabilityPollFuture).when(mockScheduler).scheduleWithFixedDelay(any(), anyInt(), anyInt(), any());
source = new WfsSource(clientBuilderFactory, encryptionService, mockScheduler);
source.setId(WFS_ID);
source.setFilterAdapter(new GeotoolsFilterAdapterImpl());
source.setContext(mockContext);
source.setWfsMetacardTypeRegistry(mockWfsMetacardTypeRegistry);
source.setMetacardTypeEnhancers(Collections.emptyList());
source.setMetacardMappers(metacardMappers);
source.setPollInterval(10);
source.setWfsUrl(SAMPLE_WFS_URL);
source.setSupportsStartIndex(false);
source.setForceAllGeometryOperands(forceAllGeometryOperands);
source.init();
}
use of org.codice.ddf.cxf.client.ClientBuilderFactory in project ddf by codice.
the class CrlGeneratorTest method testGettingDemCrlFromUrl.
@Test
public void testGettingDemCrlFromUrl() throws Exception {
ClientBuilderFactory clientBuilderFactory = getCxfClient(demEncodedCrl);
CrlGenerator crlGenerator = new CrlGenerator(clientBuilderFactory, eventAdmin);
crlGenerator.setSecurityLogger(mock(SecurityLogger.class));
crlGenerator.setCrlLocationUrl("https://testurl:8993");
crlGenerator.setCrlByUrlEnabled(true);
crlGenerator.run();
InputStream inputStream = new FileInputStream(new File(Paths.get(CrlGenerator.crlFileLocation + CrlGenerator.DEM_CRL).toString()));
byte[] encoded = new byte[inputStream.available()];
inputStream.read(encoded);
assertTrue(Arrays.equals(demEncodedCrl, encoded));
}
use of org.codice.ddf.cxf.client.ClientBuilderFactory in project ddf by codice.
the class CrlGeneratorTest method testSetCrlByUrlEnabled.
@Test
public void testSetCrlByUrlEnabled() {
ClientBuilderFactory clientBuilderFactory = getCxfClient(demEncodedCrl);
ScheduledExecutorService scheduler = mock(ScheduledExecutorService.class);
CrlGenerator crlGenerator = new CrlGenerator(clientBuilderFactory, eventAdmin, scheduler);
crlGenerator.setSecurityLogger(mock(SecurityLogger.class));
crlGenerator.setCrlByUrlEnabled(false);
Mockito.verify(scheduler, times(0)).submit(any(Callable.class));
crlGenerator.setCrlByUrlEnabled(true);
Mockito.verify(scheduler, times(0)).submit(any(Callable.class));
}
Aggregations