public SendEvent( TransformerManager transformerManager, GetRecordsType request, QueryRequest query) throws CswException { URI deliveryMethodUrl; if (request.getResponseHandler() != null && !request.getResponseHandler().isEmpty()) { try { deliveryMethodUrl = new URI(request.getResponseHandler().get(0)); } catch (URISyntaxException e) { throw new CswException("Invalid ResponseHandler URL", e); } } else { String msg = "Subscriptions require a ResponseHandler URL to be specified"; LOGGER.error(msg); throw new CswException(msg); } this.transformerManager = transformerManager; this.query = query; this.callbackUrl = deliveryMethodUrl; this.request = request; this.outputSchema = request.getOutputSchema(); this.mimeType = request.getOutputFormat(); QueryType queryType = (QueryType) request.getAbstractQuery().getValue(); this.elementName = queryType.getElementName(); this.elementSetType = (queryType.getElementSetName() != null) ? queryType.getElementSetName().getValue() : null; this.resultType = request.getResultType() == null ? ResultType.HITS : request.getResultType(); SecureCxfClientFactory<CswSubscribe> cxfClientFactory = new SecureCxfClientFactory<>(callbackUrl.toString(), CswSubscribe.class); webClient = cxfClientFactory.getWebClient(); }
@Before public void setUp() throws Exception { System.setProperty("ddf.home", "."); callbackURI = new URL("https://localhost:12345/services/csw/subscription/event"); ObjectFactory objectFactory = new ObjectFactory(); request = new GetRecordsType(); request.setOutputSchema(CswConstants.CSW_OUTPUT_SCHEMA); request.setResultType(ResultType.RESULTS); request.getResponseHandler().add(callbackURI.toString()); queryType = new QueryType(); elementSetNameType = new ElementSetNameType(); elementSetNameType.setValue(ElementSetType.BRIEF); queryType.setElementSetName(elementSetNameType); request.setAbstractQuery(objectFactory.createAbstractQuery(queryType)); transformerManager = mock(TransformerManager.class); transformer = mock(QueryResponseTransformer.class); binaryContent = mock(BinaryContent.class); when(transformerManager.getTransformerBySchema( Matchers.contains(CswConstants.CSW_OUTPUT_SCHEMA))) .thenReturn(transformer); when(transformer.transform(any(SourceResponse.class), anyMap())).thenReturn(binaryContent); when(binaryContent.getByteArray()).thenReturn("byte array with message contents".getBytes()); query = mock(QueryRequest.class); metacard = mock(Metacard.class); webclient = mock(WebClient.class); mockCxfClientFactory = mock(SecureCxfClientFactory.class); response = mock(Response.class); subject = mock(Subject.class); mockSecurity = mock(Security.class); headers.put(Subject.class.toString(), Arrays.asList(new Subject[] {subject})); AccessPlugin accessPlugin = mock(AccessPlugin.class); accessPlugins.add(accessPlugin); when(mockCxfClientFactory.getWebClient()).thenReturn(webclient); // when(webclient.head()).thenReturn(response); when(webclient.invoke(anyString(), any(QueryResponse.class))).thenReturn(response); when(response.getHeaders()).thenReturn(headers); when(accessPlugin.processPostQuery(any(QueryResponse.class))) .thenAnswer( new Answer<QueryResponse>() { @Override public QueryResponse answer(InvocationOnMock invocationOnMock) throws Throwable { return (QueryResponse) invocationOnMock.getArguments()[0]; } }); sendEvent = new SendEventExtension(transformerManager, request, query, mockCxfClientFactory); sendEvent.setSubject(subject); }