use of org.codice.ddf.cxf.client.impl.ClientBuilderImpl in project ddf by codice.
the class CswSourceTest method getCswSource.
private AbstractCswSource getCswSource(Csw csw, BundleContext context, String contentMapping, String queryTypeQName, String queryTypePrefix, EncryptionService encryptionService, Permissions permissions) {
CswSourceConfiguration cswSourceConfiguration = getStandardCswSourceConfiguration(contentMapping, queryTypeQName, queryTypePrefix, encryptionService, permissions);
cswSourceConfiguration.putMetacardCswMapping(Metacard.CONTENT_TYPE, contentMapping);
SecureCxfClientFactory<Csw> mockFactory = mock(SecureCxfClientFactory.class);
doReturn(csw).when(mockFactory).getClient();
doReturn(csw).when(mockFactory).getClientForSubject(any(Subject.class));
doReturn(csw).when(mockFactory).getClientForSystemSubject(any(Subject.class));
ClientBuilderFactory clientBuilderFactory = mock(ClientBuilderFactory.class);
ClientBuilder<Csw> clientBuilder = new ClientBuilderImpl<Csw>(mock(OAuthSecurity.class), mock(SamlSecurity.class), mock(SecurityLogger.class), mock(SecurityManager.class)) {
@Override
public SecureCxfClientFactory<Csw> build() {
return mockFactory;
}
};
when(clientBuilderFactory.<Csw>getClientBuilder()).thenReturn(clientBuilder);
CswSourceStub cswSource = new CswSourceStub(mockContext, cswSourceConfiguration, mockProvider, clientBuilderFactory, encryptionService, new Security(), permissions);
cswSource.setFilterAdapter(new GeotoolsFilterAdapterImpl());
cswSource.setFilterBuilder(builder);
cswSource.setContext(context);
cswSource.setOutputSchema(CswConstants.CSW_OUTPUT_SCHEMA);
cswSource.setAvailabilityTask(mockAvailabilityTask);
cswSource.configureCswSource();
return cswSource;
}
use of org.codice.ddf.cxf.client.impl.ClientBuilderImpl in project ddf by codice.
the class WfsSourceTest method getWfsSource.
private WfsSource getWfsSource(final String schema, final FilterCapabilities filterCapabilities, final int numFeatures, final boolean throwExceptionOnDescribeFeatureType, boolean prefix, int numReturned) throws WfsException {
mockFactory = mock(SecureCxfClientFactory.class);
when(mockFactory.getClient()).thenReturn(mockWfs);
ClientBuilder<Wfs> clientBuilder = new ClientBuilderImpl<Wfs>(mock(OAuthSecurity.class), mock(SamlSecurity.class), mock(SecurityLogger.class), mock(SecurityManager.class)) {
@Override
public SecureCxfClientFactory<Wfs> build() {
return mockFactory;
}
};
when(mockClientBuilderFactory.<Wfs>getClientBuilder()).thenReturn(clientBuilder);
// GetCapabilities Response
when(mockWfs.getCapabilities(any(GetCapabilitiesRequest.class))).thenReturn(mockCapabilities);
when(mockFeatureCollection.getMembers()).thenAnswer(new Answer<List<Metacard>>() {
@Override
public List<Metacard> answer(InvocationOnMock invocation) {
// Create as many metacards as there are features
List<Metacard> metacards = new ArrayList<>(numFeatures);
for (int i = 0; i < numFeatures; i++) {
MetacardImpl mc = new MetacardImpl();
mc.setId("ID_" + (i + 1));
metacards.add(mc);
}
return metacards;
}
});
if (numReturned != NULL_NUM_RETURNED) {
when(mockFeatureCollection.getNumberReturned()).thenReturn(BigInteger.valueOf(numReturned));
} else {
when(mockFeatureCollection.getNumberReturned()).thenReturn(null);
}
when(mockWfs.getFeature(any(GetFeatureType.class))).thenReturn(mockFeatureCollection);
mockCapabilities.setFilterCapabilities(filterCapabilities);
when(mockAvailabilityTask.isAvailable()).thenReturn(true);
mockCapabilities.setFeatureTypeList(new FeatureTypeListType());
for (int ii = 0; ii < numFeatures; ii++) {
FeatureTypeType feature = new FeatureTypeType();
QName qName;
if (prefix) {
qName = new QName("http://example.com", SAMPLE_FEATURE_NAME + ii, "Prefix" + ii);
} else {
qName = new QName("http://example.com", SAMPLE_FEATURE_NAME + ii);
}
feature.setName(qName);
feature.setDefaultCRS(GeospatialUtil.EPSG_4326_URN);
mockCapabilities.getFeatureTypeList().getFeatureType().add(feature);
}
XmlSchema xmlSchema = null;
if (StringUtils.isNotBlank(schema)) {
XmlSchemaCollection schemaCollection = new XmlSchemaCollection();
WfsUriResolver wfsUriResolver = new WfsUriResolver();
wfsUriResolver.setGmlNamespace(Wfs20Constants.GML_3_2_NAMESPACE);
wfsUriResolver.setWfsNamespace(Wfs20Constants.WFS_2_0_NAMESPACE);
schemaCollection.setSchemaResolver(wfsUriResolver);
xmlSchema = schemaCollection.read(new StreamSource(new ByteArrayInputStream(schema.getBytes())));
}
if (throwExceptionOnDescribeFeatureType) {
when(mockWfs.describeFeatureType(any(DescribeFeatureTypeRequest.class))).thenThrow(new WfsException(""));
} else {
when(mockWfs.describeFeatureType(any(DescribeFeatureTypeRequest.class))).thenReturn(xmlSchema);
}
final ScheduledFuture<?> mockAvailabilityPollFuture = mock(ScheduledFuture.class);
doReturn(mockAvailabilityPollFuture).when(mockScheduler).scheduleWithFixedDelay(any(), anyInt(), anyInt(), any());
WfsSource wfsSource = new WfsSource(mockClientBuilderFactory, encryptionService, mockScheduler);
wfsSource.setContext(mockContext);
wfsSource.setFilterAdapter(new GeotoolsFilterAdapterImpl());
wfsSource.setFeatureCollectionReader(mockReader);
wfsSource.setMetacardToFeatureMapper(metacardMappers);
wfsSource.setPollInterval(10);
wfsSource.setWfsUrl(SAMPLE_WFS_URL);
wfsSource.init();
return wfsSource;
}
use of org.codice.ddf.cxf.client.impl.ClientBuilderImpl in project ddf by codice.
the class URLResourceReaderTest method testGetWebClientWithOauth.
@Test
public void testGetWebClientWithOauth() throws URISyntaxException {
SecureCxfClientFactory<WebClient> cxfClientFactory = mock(SecureCxfClientFactory.class);
when(cxfClientFactory.getWebClient()).thenReturn(mock(WebClient.class));
ClientBuilderFactory 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 cxfClientFactory;
}
};
when(clientBuilderFactory.<WebClient>getClientBuilder()).thenReturn(clientBuilder);
URLResourceReader urlResourceReader = new URLResourceReader(mimeTypeMapper, clientBuilderFactory);
Map<String, Serializable> properties = ImmutableMap.of("id", "mysource", "oauthDiscoveryUrl", "https://keycloak:8080/discovery-url", "oauthClientId", "client-id", "oauthClientSecret", "client-secret", "oauthFlow", "code");
urlResourceReader.getWebClient(new URI("https://myurl.com"), properties);
verify(clientBuilderFactory, times(1)).getClientBuilder();
}
use of org.codice.ddf.cxf.client.impl.ClientBuilderImpl in project ddf by codice.
the class URLResourceReaderTest method testGetWebClientWithUsernameAndPassword.
@Test
public void testGetWebClientWithUsernameAndPassword() throws URISyntaxException {
SecureCxfClientFactory<WebClient> cxfClientFactory = mock(SecureCxfClientFactory.class);
when(cxfClientFactory.getWebClient()).thenReturn(mock(WebClient.class));
ClientBuilderFactory 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 cxfClientFactory;
}
};
when(clientBuilderFactory.<WebClient>getClientBuilder()).thenReturn(clientBuilder);
URLResourceReader urlResourceReader = new URLResourceReader(mimeTypeMapper, clientBuilderFactory);
Map<String, Serializable> properties = ImmutableMap.of("username", "myusername", "password", "mypassword");
urlResourceReader.getWebClient(new URI("https://myurl.com"), properties);
verify(clientBuilderFactory, times(1)).getClientBuilder();
}
use of org.codice.ddf.cxf.client.impl.ClientBuilderImpl in project ddf by codice.
the class SolrRestTest method setUp.
@Before
public void setUp() {
EncryptionService encryptionService = mock(EncryptionService.class);
when(encryptionService.decrypt(anyString())).thenReturn("test");
ClientBuilderFactory clientBuilderFactory = mock(ClientBuilderFactory.class);
SecureCxfClientFactory secureCxfClientFactory = mock(SecureCxfClientFactory.class);
ClientBuilder clientBuilder = new ClientBuilderImpl(mock(OAuthSecurity.class), mock(SamlSecurity.class), mock(SecurityLogger.class), mock(SecurityManager.class)) {
@Override
public SecureCxfClientFactory build() {
return secureCxfClientFactory;
}
};
when(clientBuilderFactory.getClientBuilder()).thenReturn(clientBuilder);
solrRest = new SolrRest(clientBuilderFactory, encryptionService);
}
Aggregations